ncursesw 0.9.2 → 1.2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST +2 -0
- data/README +49 -12
- data/THANKS +2 -1
- data/VERSION +1 -1
- data/extconf.rb +8 -2
- data/form_wrap.c +78 -78
- data/form_wrap.h +4 -5
- data/lib/ncursesw.rb +22 -2
- data/menu_wrap.c +1144 -0
- data/menu_wrap.h +49 -0
- data/ncurses_wrap.c +40 -5
- data/ncurses_wrap.h +4 -2
- metadata +5 -3
data/MANIFEST
CHANGED
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
$Id: README,v 1.
|
1
|
+
$Id: README,v 1.16 2009/05/03 14:13:27 t-peters Exp $
|
2
2
|
------------------------------------------------------------------------
|
3
3
|
This directory contains a ruby module for accessing the FSF's ncurses
|
4
4
|
library.
|
@@ -47,9 +47,10 @@ This README is organized into the following parts:
|
|
47
47
|
- The WINDOW class
|
48
48
|
- The panel Library
|
49
49
|
- The form Library
|
50
|
+
- The menu Library
|
51
|
+
- Locale handling
|
50
52
|
- Ncurses and Ruby Threads
|
51
53
|
- Example programs
|
52
|
-
- Applications using ncurses-ruby
|
53
54
|
|
54
55
|
General Ncurses Literature
|
55
56
|
--------------------------
|
@@ -211,6 +212,10 @@ module Ncurses
|
|
211
212
|
class FIELD; end
|
212
213
|
class FIELDTYPE; end
|
213
214
|
end
|
215
|
+
module Menu
|
216
|
+
class MENU; end
|
217
|
+
class ITEM; end
|
218
|
+
end
|
214
219
|
end
|
215
220
|
|
216
221
|
|
@@ -288,6 +293,48 @@ function arguments. See the example form2.rb for more details.
|
|
288
293
|
The functions form_userptr and field_userptr are not supported. Use
|
289
294
|
form.user_object and field.user_object to store Ruby objects instead.
|
290
295
|
|
296
|
+
The menu Library
|
297
|
+
================
|
298
|
+
|
299
|
+
The menu library was wrapped inside the Ncurses:Menu module. All
|
300
|
+
menu functions are implemented as module functions in the module
|
301
|
+
Ncurses::Menu. In addition, all functions for which the first
|
302
|
+
parameter is one of the objects are also implemented as an instance
|
303
|
+
method of the respective class. For example, instead of calling
|
304
|
+
post_menu(menu), you can use menu.post_menu().
|
305
|
+
|
306
|
+
Two objects are defined in the Ncurses:Menu module:
|
307
|
+
1. MENU
|
308
|
+
2. ITEM
|
309
|
+
|
310
|
+
They are wrapping actual ncurses pointers and should be use whenever a
|
311
|
+
pointer to one of these types is expected in function calls.
|
312
|
+
|
313
|
+
All menu constants are defined in the module as Ruby constants with
|
314
|
+
the same name as the curses constants.
|
315
|
+
|
316
|
+
Constructors for MENU and ITEM objects are also provided, and they
|
317
|
+
expect the same parameters as new_menu and new_item curses functions.
|
318
|
+
|
319
|
+
You must provide a Ruby block whenever a function pointer is expected
|
320
|
+
in curses function arguments.
|
321
|
+
|
322
|
+
The functions menu_userptr and item_userptr are not supported. Use
|
323
|
+
menu.user_object and item.user_object to store Ruby objects instead.
|
324
|
+
|
325
|
+
Locale handling
|
326
|
+
===============
|
327
|
+
|
328
|
+
The C library function setlocale is not technically an Ncurses function.
|
329
|
+
However, it is used by many ncurses programs, and for this purpose,
|
330
|
+
a wrapper for this function is also included in ncurses-ruby.
|
331
|
+
|
332
|
+
The function is implemented as a module function Ncurses.ruby, and
|
333
|
+
expects two arguments, an Integer and a String. It returns a string.
|
334
|
+
The constants that can be used as the Integer argument are also wrapped
|
335
|
+
as constants in the Ncurses module. See the manual page for setlocale
|
336
|
+
for documentation of this function.
|
337
|
+
|
291
338
|
Ncurses and Ruby Threads
|
292
339
|
========================
|
293
340
|
|
@@ -306,13 +353,3 @@ Directory "examples" contains a few example programs demonstrating how
|
|
306
353
|
to use the ncurses library with ruby. Be sure to read the file
|
307
354
|
"examples/LICENSES_for_examples".
|
308
355
|
|
309
|
-
|
310
|
-
Applications using ncurses-ruby
|
311
|
-
===============================
|
312
|
-
|
313
|
-
aeditor (v. 0.x) - Pair programming editor, http://metaeditor.sourceforge.net/
|
314
|
-
raggle - RSS aggregator, http://www.raggle.org/about/
|
315
|
-
ruvi - Editor, http://ruvi.rubyforge.org/
|
316
|
-
diakonos - Editor, http://purepistos.net/diakonos/
|
317
|
-
tpp - text-based presentation program, http://synflood.at/tpp/
|
318
|
-
yapo - ports overview for CRUX linux distribution, http://jue.li/crux/yapo/
|
data/THANKS
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
$Id: THANKS,v 1.
|
1
|
+
$Id: THANKS,v 1.9 2009/05/03 10:37:54 t-peters Exp $
|
2
2
|
|
3
3
|
A list of people that helped me with ncurses-ruby
|
4
4
|
|
@@ -12,3 +12,4 @@ Andreas Schwarz
|
|
12
12
|
Simon Strandgaard
|
13
13
|
Paul Duncan
|
14
14
|
Tim Sutherland
|
15
|
+
Earle Clubb
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.4
|
data/extconf.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# ncurses-ruby is a ruby module for accessing the FSF's ncurses library
|
4
4
|
# (C) 2002, 2004 Tobias Peters <t-peters@users.berlios.de>
|
5
|
-
# (C) 2005 Tobias Herzke
|
5
|
+
# (C) 2005, 2009 Tobias Herzke
|
6
6
|
#
|
7
7
|
# This module is free software; you can redistribute it and/or
|
8
8
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# License along with this module; if not, write to the Free Software
|
19
19
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
20
|
|
21
|
-
# $Id: extconf.rb,v 1.
|
21
|
+
# $Id: extconf.rb,v 1.14 2009/05/03 14:13:27 t-peters Exp $
|
22
22
|
|
23
23
|
require "mkmf"
|
24
24
|
|
@@ -26,6 +26,8 @@ $CFLAGS += " -g"
|
|
26
26
|
$CXXFLAGS = $CFLAGS
|
27
27
|
|
28
28
|
have_header("unistd.h")
|
29
|
+
have_header("locale.h")
|
30
|
+
|
29
31
|
if have_header("ncurses.h")
|
30
32
|
curses_header = "ncurses.h"
|
31
33
|
elsif have_header("ncurses/curses.h")
|
@@ -127,5 +129,9 @@ puts "checking for the form library..."
|
|
127
129
|
if have_header("form.h")
|
128
130
|
have_library("formw", "new_form")
|
129
131
|
end
|
132
|
+
puts "checking for the menu library..."
|
133
|
+
if have_header("menu.h")
|
134
|
+
have_library("menu", "new_menu")
|
135
|
+
end
|
130
136
|
|
131
137
|
create_makefile('ncursesw_bin')
|
data/form_wrap.c
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
*
|
7
7
|
* Changes:
|
8
8
|
* (C) 2004 Tobias Peters
|
9
|
-
* (C) 2005 Tobias Herzke
|
9
|
+
* (C) 2005 2009 Tobias Herzke
|
10
10
|
*
|
11
11
|
* This module is free software; you can redistribute it and/or
|
12
12
|
* modify it under the terms of the GNU Lesser General Public
|
@@ -394,7 +394,7 @@ static void reg_proc(void* owner, int hook, VALUE proc) {
|
|
394
394
|
*/
|
395
395
|
static VALUE rbncurs_m_new_form(VALUE dummy, VALUE rb_field_array)
|
396
396
|
{
|
397
|
-
long n =
|
397
|
+
long n = rbncurs_array_length(rb_field_array);
|
398
398
|
/* Will ncurses free this array? If not, must do it after calling free_form(). */
|
399
399
|
FIELD** fields = ALLOC_N(FIELD*, (n+1));
|
400
400
|
long i;
|
@@ -618,7 +618,7 @@ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
|
|
618
618
|
rb_raise(rb_eArgError, "TYPE_ENUM requires three additional arguments");
|
619
619
|
}
|
620
620
|
else {
|
621
|
-
int n =
|
621
|
+
int n = rbncurs_array_length(arg3);
|
622
622
|
/* Will ncurses free this array of strings in free_field()? */
|
623
623
|
char** list = ALLOC_N(char*, n+1);
|
624
624
|
int i;
|
@@ -777,7 +777,7 @@ static VALUE rbncurs_m_set_max_field(VALUE dummy, VALUE rb_field, VALUE max)
|
|
777
777
|
* form_field
|
778
778
|
*/
|
779
779
|
static VALUE rbncurs_c_set_form_fields(VALUE rb_form, VALUE rb_field_array) {
|
780
|
-
long n =
|
780
|
+
long n = rbncurs_array_length(rb_field_array);
|
781
781
|
/* If ncurses does not free memory used by the previous array of strings, */
|
782
782
|
/* we will have to do it now. */
|
783
783
|
FIELD** fields = ALLOC_N(FIELD*, (n+1));
|
@@ -1125,11 +1125,11 @@ static void* make_arg(va_list* ap) {
|
|
1125
1125
|
VALUE argc = rb_funcall(proc, rb_intern("arity"),0);
|
1126
1126
|
VALUE args = get_proc(field, FIELDTYPE_ARGS);
|
1127
1127
|
if (args != Qnil) {
|
1128
|
-
if (NUM2INT(argc)-1 !=
|
1128
|
+
if (NUM2INT(argc)-1 != rbncurs_array_length(args)) {
|
1129
1129
|
char msg[500];
|
1130
1130
|
snprintf(msg, 500, "The validation functions for this field type need %d additional arguments.",NUM2INT(argc)-1);
|
1131
1131
|
msg[499]=0;
|
1132
|
-
rb_raise(rb_eArgError,
|
1132
|
+
rb_raise(rb_eArgError, msg);
|
1133
1133
|
}
|
1134
1134
|
}
|
1135
1135
|
}
|
@@ -1258,12 +1258,12 @@ void init_form(void)
|
|
1258
1258
|
FORM_SNG_FUNC(data_ahead,1);
|
1259
1259
|
FORM_SNG_FUNC(data_behind,1);
|
1260
1260
|
FORM_SNG_FUNC(dup_field,3);
|
1261
|
-
FORM_SNG_FUNC(dynamic_field_info,
|
1261
|
+
FORM_SNG_FUNC(dynamic_field_info,4);
|
1262
1262
|
FORM_SNG_FUNC(field_arg,1);
|
1263
|
-
FORM_SNG_FUNC(field_back,
|
1263
|
+
FORM_SNG_FUNC(field_back,1);
|
1264
1264
|
FORM_SNG_FUNC(field_buffer,2);
|
1265
1265
|
FORM_SNG_FUNC(field_count,1);
|
1266
|
-
FORM_SNG_FUNC(field_fore,
|
1266
|
+
FORM_SNG_FUNC(field_fore,1);
|
1267
1267
|
FORM_SNG_FUNC(field_index,1);
|
1268
1268
|
FORM_SNG_FUNC(field_info,7);
|
1269
1269
|
FORM_SNG_FUNC(field_init,1);
|
@@ -1271,7 +1271,7 @@ void init_form(void)
|
|
1271
1271
|
FORM_SNG_FUNC(field_opts,1);
|
1272
1272
|
FORM_SNG_FUNC(field_opts_off,2);
|
1273
1273
|
FORM_SNG_FUNC(field_opts_on,2);
|
1274
|
-
FORM_SNG_FUNC(field_pad,
|
1274
|
+
FORM_SNG_FUNC(field_pad,1);
|
1275
1275
|
FORM_SNG_FUNC(field_status,1);
|
1276
1276
|
FORM_SNG_FUNC(field_term,1);
|
1277
1277
|
FORM_SNG_FUNC(field_type,1);
|
@@ -1349,40 +1349,40 @@ void init_form(void)
|
|
1349
1349
|
rb_define_singleton_method(cFORM, "new",
|
1350
1350
|
(&rbncurs_m_new_form),
|
1351
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);
|
1352
|
+
RB_CLASS_METH(cFORM, NULL, current_field,0);
|
1353
|
+
RB_CLASS_METH(cFORM, NULL, data_ahead,0);
|
1354
|
+
RB_CLASS_METH(cFORM, NULL, data_behind,0);
|
1355
|
+
RB_CLASS_METH(cFORM, NULL, dup_field,2);
|
1356
|
+
RB_CLASS_METH(cFORM, NULL, field_count,0);
|
1357
|
+
RB_CLASS_METH(cFORM, NULL, field_init,0);
|
1358
|
+
RB_CLASS_METH(cFORM, NULL, field_term,0);
|
1359
|
+
RB_CLASS_METH(cFORM, "driver", form_driver,1);
|
1360
|
+
RB_CLASS_METH(cFORM, "fields", form_fields,0);
|
1361
|
+
RB_CLASS_METH(cFORM, "init", form_init,0);
|
1362
|
+
RB_CLASS_METH(cFORM, "opts", form_opts,0);
|
1363
|
+
RB_CLASS_METH(cFORM, "opts_off", form_opts_off,1);
|
1364
|
+
RB_CLASS_METH(cFORM, "opts_on", form_opts_on,1);
|
1365
|
+
RB_CLASS_METH(cFORM, "page", form_page,0);
|
1366
|
+
RB_CLASS_METH(cFORM, "sub", form_sub,0);
|
1367
|
+
RB_CLASS_METH(cFORM, "term", form_term,0);
|
1368
|
+
/* RB_CLASS_METH(cFORM, "userptr", form_userptr,0); */
|
1369
|
+
RB_CLASS_METH(cFORM, "win", form_win,0);
|
1370
|
+
RB_CLASS_METH(cFORM, "free", free_form,0);
|
1371
|
+
RB_CLASS_METH(cFORM, "pos_cursor", pos_form_cursor,0);
|
1372
|
+
RB_CLASS_METH(cFORM, "post", post_form,0);
|
1373
|
+
RB_CLASS_METH(cFORM, "scale", scale_form,2);
|
1374
|
+
RB_CLASS_METH(cFORM, "current_field=", set_current_field,1);
|
1375
|
+
RB_CLASS_METH(cFORM, "field_init=", set_field_init,1);
|
1376
|
+
RB_CLASS_METH(cFORM, "field_term=", set_field_term,1);
|
1377
|
+
RB_CLASS_METH(cFORM, "fields=", set_form_fields,1);
|
1378
|
+
RB_CLASS_METH(cFORM, "init=", set_form_init,1);
|
1379
|
+
RB_CLASS_METH(cFORM, "opts=", set_form_opts,1);
|
1380
|
+
RB_CLASS_METH(cFORM, "page=", set_form_page,1);
|
1381
|
+
RB_CLASS_METH(cFORM, "sub=", set_form_sub,1);
|
1382
|
+
RB_CLASS_METH(cFORM, "term=", set_form_term,1);
|
1383
|
+
/* RB_CLASS_METH(cFORM, "userptr=", set_form_userptr,1); */
|
1384
|
+
RB_CLASS_METH(cFORM, "win=", set_form_win,1);
|
1385
|
+
RB_CLASS_METH(cFORM, "unpost", unpost_form,0);
|
1386
1386
|
|
1387
1387
|
/* Fields */
|
1388
1388
|
rb_iv_set(mForm, "@fields_hash", rb_hash_new());
|
@@ -1390,37 +1390,37 @@ void init_form(void)
|
|
1390
1390
|
rb_define_singleton_method(cFIELD, "new",
|
1391
1391
|
(&rbncurs_m_new_field),
|
1392
1392
|
6);
|
1393
|
-
RB_CLASS_METH(cFIELD, dup_field,2);
|
1394
|
-
RB_CLASS_METH(cFIELD, dynamic_field_info,
|
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);
|
1393
|
+
RB_CLASS_METH(cFIELD, "dup", dup_field,2);
|
1394
|
+
RB_CLASS_METH(cFIELD, "dynamic_info", dynamic_field_info,3);
|
1395
|
+
RB_CLASS_METH(cFIELD, "arg", field_arg,0);
|
1396
|
+
RB_CLASS_METH(cFIELD, "back", field_back,1);
|
1397
|
+
RB_CLASS_METH(cFIELD, "buffer", field_buffer,1);
|
1398
|
+
RB_CLASS_METH(cFIELD, "fore", field_fore,1);
|
1399
|
+
RB_CLASS_METH(cFIELD, "index", field_index,0);
|
1400
|
+
RB_CLASS_METH(cFIELD, "info", field_info,6);
|
1401
|
+
RB_CLASS_METH(cFIELD, "just", field_just,0);
|
1402
|
+
RB_CLASS_METH(cFIELD, "opts", field_opts,0);
|
1403
|
+
RB_CLASS_METH(cFIELD, "opts_off", field_opts_off,1);
|
1404
|
+
RB_CLASS_METH(cFIELD, "opts_on", field_opts_on,1);
|
1405
|
+
RB_CLASS_METH(cFIELD, "pad", field_pad,1);
|
1406
|
+
RB_CLASS_METH(cFIELD, "status", field_status,0);
|
1407
|
+
RB_CLASS_METH(cFIELD, "type", field_type,0);
|
1408
|
+
/* RB_CLASS_METH(cFIELD, "userptr", field_userptr,0); */
|
1409
|
+
RB_CLASS_METH(cFIELD, "free", free_field,0);
|
1410
|
+
RB_CLASS_METH(cFIELD, "link", link_field,2);
|
1411
|
+
RB_CLASS_METH(cFIELD, "move", move_field,2);
|
1412
|
+
RB_CLASS_METH(cFIELD, NULL, new_page,0);
|
1413
|
+
RB_CLASS_METH(cFIELD, "back=", set_field_back,1);
|
1414
|
+
RB_CLASS_METH(cFIELD, "set_buffer", set_field_buffer,2);
|
1415
|
+
RB_CLASS_METH(cFIELD, "fore=", set_field_fore,1);
|
1416
|
+
RB_CLASS_METH(cFIELD, "just=", set_field_just,1);
|
1417
|
+
RB_CLASS_METH(cFIELD, "opts=", set_field_opts,1);
|
1418
|
+
RB_CLASS_METH(cFIELD, "pad=", set_field_pad,1);
|
1419
|
+
RB_CLASS_METH(cFIELD, "status=", set_field_status,1);
|
1420
|
+
RB_CLASS_METH(cFIELD, "set_type", set_field_type,-1);
|
1421
|
+
/* RB_CLASS_METH(cFIELD, "userptr=", set_field_userptr,1); */
|
1422
|
+
RB_CLASS_METH(cFIELD, "max_field=", set_max_field,1);
|
1423
|
+
RB_CLASS_METH(cFIELD, "new_page=", set_new_page,1);
|
1424
1424
|
|
1425
1425
|
|
1426
1426
|
|
@@ -1431,9 +1431,9 @@ void init_form(void)
|
|
1431
1431
|
rb_define_singleton_method(cFIELDTYPE, "new",
|
1432
1432
|
(&rbncurs_m_new_fieldtype),
|
1433
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);
|
1434
|
+
RB_CLASS_METH(cFIELDTYPE, "free", free_fieldtype,0);
|
1435
|
+
RB_CLASS_METH(cFIELDTYPE, "link", link_fieldtype,1);
|
1436
|
+
RB_CLASS_METH(cFIELDTYPE, "set_choice", set_fieldtype_choice,2);
|
1437
1437
|
|
1438
1438
|
/* Create predefined types */
|
1439
1439
|
rb_define_const(mForm, "TYPE_ALNUM", wrap_fieldtype(TYPE_ALNUM));
|
data/form_wrap.h
CHANGED
@@ -47,11 +47,10 @@ typedef struct {
|
|
47
47
|
#name, \
|
48
48
|
&rbncurs_m_ ## name, \
|
49
49
|
nargs)
|
50
|
-
#define RB_CLASS_METH(class, name, nargs)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
nargs);
|
50
|
+
#define RB_CLASS_METH(class, alt_name, name, nargs) \
|
51
|
+
rb_define_method(class, #name, (&rbncurs_c_ ## name), nargs); \
|
52
|
+
if (alt_name != NULL) \
|
53
|
+
rb_define_method(class, alt_name, (&rbncurs_c_ ## name), nargs); \
|
55
54
|
|
56
55
|
void init_req_constants();
|
57
56
|
void init_just_constants();
|
data/lib/ncursesw.rb
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
# License along with this module; if not, write to the Free Software
|
18
18
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
19
|
|
20
|
-
# $Id: ncurses.rb,v 1.
|
20
|
+
# $Id: ncurses.rb,v 1.8 2009/05/03 10:37:54 t-peters Exp $
|
21
21
|
|
22
22
|
require "ncursesw_bin.so"
|
23
23
|
|
@@ -109,7 +109,7 @@ module Ncurses
|
|
109
109
|
class FORM
|
110
110
|
attr_reader :user_object
|
111
111
|
|
112
|
-
# This placeholder replaces the
|
112
|
+
# This placeholder replaces the form_userptr function in curses
|
113
113
|
def user_object=(obj)
|
114
114
|
@user_object = obj
|
115
115
|
end
|
@@ -127,6 +127,26 @@ module Ncurses
|
|
127
127
|
class FIELDTYPE
|
128
128
|
end
|
129
129
|
end
|
130
|
+
|
131
|
+
module Menu
|
132
|
+
class MENU
|
133
|
+
attr_reader :user_object
|
134
|
+
|
135
|
+
# This placeholder replaces the menu_userptr function in curses
|
136
|
+
def user_object=(obj)
|
137
|
+
@user_object = obj
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class ITEM
|
142
|
+
attr_reader :user_object
|
143
|
+
|
144
|
+
# This placeholder replaces the item_userptr function in curses
|
145
|
+
def user_object=(obj)
|
146
|
+
@user_object = obj
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
130
150
|
end
|
131
151
|
def Ncurses.inchnstr(str,n)
|
132
152
|
Ncurses.winchnstr(Ncurses.stdscr, str, n)
|
data/menu_wrap.c
ADDED
@@ -0,0 +1,1144 @@
|
|
1
|
+
/*
|
2
|
+
* This is a curses menu wrapper as part of ncurses-ruby.
|
3
|
+
* It borrows heavily from form_wrap.c.
|
4
|
+
* Contributed by Earle Clubb <eclubb@valcom.com>
|
5
|
+
* Valcom Inc. <http://www.valcom.com>
|
6
|
+
* Copyright 2007
|
7
|
+
*
|
8
|
+
* Modifications
|
9
|
+
* (C) 2009 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
|
+
#ifdef HAVE_MENU_H
|
28
|
+
|
29
|
+
#include "menu_wrap.h"
|
30
|
+
#include "ncurses_wrap.h"
|
31
|
+
|
32
|
+
VALUE mMenu;
|
33
|
+
VALUE cITEM;
|
34
|
+
VALUE cMENU;
|
35
|
+
|
36
|
+
void init_menu_err_codes(void)
|
37
|
+
{
|
38
|
+
/* The routine succeeded. */
|
39
|
+
MENU_DEF_CONST(E_OK);
|
40
|
+
/* System error occurred (see errno). */
|
41
|
+
MENU_DEF_CONST(E_SYSTEM_ERROR);
|
42
|
+
/* Routine detected an incorrect or out-of-range argument. */
|
43
|
+
MENU_DEF_CONST(E_BAD_ARGUMENT);
|
44
|
+
/* The menu is already posted. */
|
45
|
+
MENU_DEF_CONST(E_POSTED);
|
46
|
+
/* Routine was called from an initialization or termination function. */
|
47
|
+
MENU_DEF_CONST(E_BAD_STATE);
|
48
|
+
/* Menu is too large for its window. */
|
49
|
+
MENU_DEF_CONST(E_NO_ROOM);
|
50
|
+
/* The menu has not been posted. */
|
51
|
+
MENU_DEF_CONST(E_NOT_POSTED);
|
52
|
+
/* The menu driver code saw an unknown request code. */
|
53
|
+
MENU_DEF_CONST(E_UNKNOWN_COMMAND);
|
54
|
+
/* Character failed to match. */
|
55
|
+
MENU_DEF_CONST(E_NO_MATCH);
|
56
|
+
/* The designated item cannot be selected. */
|
57
|
+
MENU_DEF_CONST(E_NOT_SELECTABLE);
|
58
|
+
/* No items are connected to the menu. */
|
59
|
+
MENU_DEF_CONST(E_NOT_CONNECTED);
|
60
|
+
/* The menu driver could not process the request.} */
|
61
|
+
MENU_DEF_CONST(E_REQUEST_DENIED);
|
62
|
+
}
|
63
|
+
|
64
|
+
|
65
|
+
/*
|
66
|
+
* Menu driver request characters - menu_driver(3x) man page
|
67
|
+
*/
|
68
|
+
void init_menu_req_constants(void)
|
69
|
+
{
|
70
|
+
/* Move left to an item. */
|
71
|
+
MENU_DEF_CONST(REQ_LEFT_ITEM);
|
72
|
+
/* Move right to an item. */
|
73
|
+
MENU_DEF_CONST(REQ_RIGHT_ITEM);
|
74
|
+
/* Move up to an item. */
|
75
|
+
MENU_DEF_CONST(REQ_UP_ITEM);
|
76
|
+
/* Move down to an item. */
|
77
|
+
MENU_DEF_CONST(REQ_DOWN_ITEM);
|
78
|
+
/* Scroll up a line. */
|
79
|
+
MENU_DEF_CONST(REQ_SCR_ULINE);
|
80
|
+
/* Scroll down a line. */
|
81
|
+
MENU_DEF_CONST(REQ_SCR_DLINE);
|
82
|
+
/* Scroll up a page. */
|
83
|
+
MENU_DEF_CONST(REQ_SCR_UPAGE);
|
84
|
+
/* Scroll down a page. */
|
85
|
+
MENU_DEF_CONST(REQ_SCR_DPAGE);
|
86
|
+
/* Move to the first item. */
|
87
|
+
MENU_DEF_CONST(REQ_FIRST_ITEM);
|
88
|
+
/* Move to the last item. */
|
89
|
+
MENU_DEF_CONST(REQ_LAST_ITEM);
|
90
|
+
/* Move to the next item. */
|
91
|
+
MENU_DEF_CONST(REQ_NEXT_ITEM);
|
92
|
+
/* Move to the previous item. */
|
93
|
+
MENU_DEF_CONST(REQ_PREV_ITEM);
|
94
|
+
/* Select/deselect an item. */
|
95
|
+
MENU_DEF_CONST(REQ_TOGGLE_ITEM);
|
96
|
+
/* Clear the menu pattern buffer. */
|
97
|
+
MENU_DEF_CONST(REQ_CLEAR_PATTERN);
|
98
|
+
/* Delete the previous character from the pattern buffer. */
|
99
|
+
MENU_DEF_CONST(REQ_BACK_PATTERN);
|
100
|
+
/* Move to the next item matching the pattern match. */
|
101
|
+
MENU_DEF_CONST(REQ_NEXT_MATCH);
|
102
|
+
/* Move to the previous item matching the pattern match. */
|
103
|
+
MENU_DEF_CONST(REQ_PREV_MATCH);
|
104
|
+
}
|
105
|
+
|
106
|
+
|
107
|
+
/*
|
108
|
+
* Item options - mitem_opts(3x) man page
|
109
|
+
*/
|
110
|
+
void init_item_opts_constants(void)
|
111
|
+
{
|
112
|
+
/* Item may be selected during menu processing. */
|
113
|
+
MENU_DEF_CONST(O_SELECTABLE);
|
114
|
+
}
|
115
|
+
|
116
|
+
|
117
|
+
/*
|
118
|
+
* Menu options - menu_opts(3x) man page
|
119
|
+
*/
|
120
|
+
void init_menu_opts_constants(void)
|
121
|
+
{
|
122
|
+
/* Only one item can be selected for this menu. */
|
123
|
+
MENU_DEF_CONST(O_ONEVALUE);
|
124
|
+
/* Display the item descriptions when the menu is posted. */
|
125
|
+
MENU_DEF_CONST(O_SHOWDESC);
|
126
|
+
/* Display the menu in row-major order. */
|
127
|
+
MENU_DEF_CONST(O_ROWMAJOR);
|
128
|
+
/* Ignore the case when pattern-matching. */
|
129
|
+
MENU_DEF_CONST(O_IGNORECASE);
|
130
|
+
/* Move the cursor to within the item name while pattern-matching. */
|
131
|
+
MENU_DEF_CONST(O_SHOWMATCH);
|
132
|
+
/* Don’t wrap around next-item and previous-item, requests to the other end of the menu. */
|
133
|
+
MENU_DEF_CONST(O_NONCYCLIC);
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
/*
|
138
|
+
* ITEM wrapper
|
139
|
+
*/
|
140
|
+
static VALUE wrap_item(ITEM *item)
|
141
|
+
{
|
142
|
+
if (item == 0) return Qnil;
|
143
|
+
{
|
144
|
+
VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
|
145
|
+
VALUE item_address = INT2NUM((long)(item));
|
146
|
+
VALUE rb_item = rb_hash_aref(items_hash, item_address);
|
147
|
+
|
148
|
+
if (rb_item == Qnil)
|
149
|
+
{
|
150
|
+
rb_item = Data_Wrap_Struct(cITEM, 0, 0, item);
|
151
|
+
rb_iv_set(rb_item, "@destroyed", Qfalse);
|
152
|
+
rb_hash_aset(items_hash, item_address, rb_item);
|
153
|
+
}
|
154
|
+
return rb_item;
|
155
|
+
}
|
156
|
+
}
|
157
|
+
static ITEM *get_item(VALUE rb_item)
|
158
|
+
{
|
159
|
+
ITEM *item;
|
160
|
+
|
161
|
+
if (rb_item == Qnil) return 0;
|
162
|
+
if (rb_iv_get(rb_item, "@destroyed") == Qtrue)
|
163
|
+
{
|
164
|
+
rb_raise(rb_eRuntimeError, "Attempt to access a destroyed item");
|
165
|
+
return 0;
|
166
|
+
}
|
167
|
+
Data_Get_Struct(rb_item, ITEM, item);
|
168
|
+
return item;
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
/*
|
173
|
+
* MENU wrapper
|
174
|
+
*/
|
175
|
+
static VALUE wrap_menu(MENU *menu)
|
176
|
+
{
|
177
|
+
if (menu == 0) return Qnil;
|
178
|
+
{
|
179
|
+
VALUE menus_hash = rb_iv_get(mMenu, "@menus_hash");
|
180
|
+
VALUE menu_address = INT2NUM((long)(menu));
|
181
|
+
VALUE rb_menu = rb_hash_aref(menus_hash, menu_address);
|
182
|
+
|
183
|
+
if (rb_menu == Qnil)
|
184
|
+
{
|
185
|
+
rb_menu = Data_Wrap_Struct(cMENU, 0, 0, menu);
|
186
|
+
rb_iv_set(rb_menu, "@destroyed", Qfalse);
|
187
|
+
rb_hash_aset(menus_hash, menu_address, rb_menu);
|
188
|
+
}
|
189
|
+
return rb_menu;
|
190
|
+
}
|
191
|
+
}
|
192
|
+
static MENU *get_menu(VALUE rb_menu)
|
193
|
+
{
|
194
|
+
MENU *menu;
|
195
|
+
|
196
|
+
if (rb_menu == Qnil) return 0;
|
197
|
+
if (rb_iv_get(rb_menu, "@destroyed") == Qtrue)
|
198
|
+
{
|
199
|
+
rb_raise(rb_eRuntimeError, "Attempt to access a destroyed menu");
|
200
|
+
return 0;
|
201
|
+
}
|
202
|
+
Data_Get_Struct(rb_menu, MENU, menu);
|
203
|
+
return menu;
|
204
|
+
}
|
205
|
+
|
206
|
+
|
207
|
+
/*
|
208
|
+
* Proc objects are registered using hashes (one for each type of hook)
|
209
|
+
* The key in the hash is the address of the ncurses "object" and the value is
|
210
|
+
* the Proc object.
|
211
|
+
*/
|
212
|
+
#define ITEM_INIT_HOOK 0
|
213
|
+
#define ITEM_TERM_HOOK 1
|
214
|
+
#define MENU_INIT_HOOK 2
|
215
|
+
#define MENU_TERM_HOOK 3
|
216
|
+
#define PROC_HASHES_COUNT 4
|
217
|
+
static VALUE get_proc_hash(int hook)
|
218
|
+
{
|
219
|
+
VALUE arr = rb_iv_get(mMenu, "@proc_hashes");
|
220
|
+
VALUE hash = rb_ary_entry(arr, (long)hook);
|
221
|
+
|
222
|
+
if (hash == Qnil)
|
223
|
+
rb_raise(rb_eRuntimeError, "Invalid proc hash.");
|
224
|
+
return hash;
|
225
|
+
}
|
226
|
+
|
227
|
+
/*
|
228
|
+
* Returns an existing Ruby Proc for a given owning "object" and hook type.
|
229
|
+
* Qnil will be returned if no Proc was associated with the owner
|
230
|
+
*/
|
231
|
+
static VALUE get_proc(void *owner, int hook)
|
232
|
+
{
|
233
|
+
if (owner == 0) return Qnil;
|
234
|
+
{
|
235
|
+
VALUE owner_address = INT2NUM((long)(owner));
|
236
|
+
VALUE proc_hash = get_proc_hash(hook);
|
237
|
+
VALUE proc = rb_hash_aref(proc_hash, owner_address);
|
238
|
+
|
239
|
+
return proc;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
|
243
|
+
/*
|
244
|
+
* Registers the Proc object with a given owner "object" and hook type.
|
245
|
+
* If proc is Qnil, the hook is unregistered instead.
|
246
|
+
*/
|
247
|
+
static void reg_proc(void *owner, int hook, VALUE proc)
|
248
|
+
{
|
249
|
+
if (owner == NULL) return;
|
250
|
+
{
|
251
|
+
VALUE proc_hash = get_proc_hash(hook);
|
252
|
+
VALUE owner_address = INT2NUM((long)(owner));
|
253
|
+
|
254
|
+
if (proc == Qnil)
|
255
|
+
rb_hash_delete(proc_hash, owner_address);
|
256
|
+
else
|
257
|
+
rb_hash_aset(proc_hash, owner_address, proc);
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
/*
|
263
|
+
* Menu creation/destruction functions - menu_new(3X) man page
|
264
|
+
*/
|
265
|
+
static VALUE rbncurs_m_new_menu(VALUE dummy, VALUE rb_item_array)
|
266
|
+
{
|
267
|
+
long n = rbncurs_array_length(rb_item_array);
|
268
|
+
/* Will ncurses free this array? If not, must do it after calling free_menu(). */
|
269
|
+
ITEM **items = ALLOC_N(ITEM*, (n+1));
|
270
|
+
long i;
|
271
|
+
|
272
|
+
for (i=0; i<n; i++)
|
273
|
+
items[i] = get_item(rb_ary_entry(rb_item_array, i));
|
274
|
+
items[n] = NULL;
|
275
|
+
return wrap_menu(new_menu(items));
|
276
|
+
}
|
277
|
+
|
278
|
+
static VALUE rbncurs_c_free_menu(VALUE rb_menu)
|
279
|
+
{
|
280
|
+
VALUE menus_hash = rb_iv_get(mMenu, "@menus_hash");
|
281
|
+
MENU *menu = get_menu(rb_menu);
|
282
|
+
VALUE menu_address = INT2NUM((long)(menu));
|
283
|
+
|
284
|
+
rb_funcall(menus_hash, rb_intern("delete"), 1, menu_address);
|
285
|
+
rb_iv_set(rb_menu, "@destroyed", Qtrue);
|
286
|
+
return INT2NUM(free_menu(menu));
|
287
|
+
}
|
288
|
+
static VALUE rbncurs_m_free_menu(VALUE dummy, VALUE rb_menu)
|
289
|
+
{ return rbncurs_c_free_menu(rb_menu); }
|
290
|
+
|
291
|
+
|
292
|
+
/*
|
293
|
+
* Menu post/unpost functions - menu_post(3X) man page
|
294
|
+
*/
|
295
|
+
static VALUE rbncurs_c_post_menu(VALUE rb_menu)
|
296
|
+
{
|
297
|
+
MENU *menu = get_menu(rb_menu);
|
298
|
+
return INT2NUM(post_menu(menu));
|
299
|
+
}
|
300
|
+
static VALUE rbncurs_m_post_menu(VALUE dummy, VALUE rb_menu)
|
301
|
+
{ return rbncurs_c_post_menu(rb_menu); }
|
302
|
+
|
303
|
+
static VALUE rbncurs_c_unpost_menu(VALUE rb_menu)
|
304
|
+
{
|
305
|
+
MENU *menu = get_menu(rb_menu);
|
306
|
+
return INT2NUM(unpost_menu(menu));
|
307
|
+
}
|
308
|
+
static VALUE rbncurs_m_unpost_menu(VALUE dummy, VALUE rb_menu)
|
309
|
+
{ return rbncurs_c_unpost_menu(rb_menu); }
|
310
|
+
|
311
|
+
|
312
|
+
/*
|
313
|
+
* Menu driver - menu_driver(3X) man page
|
314
|
+
*/
|
315
|
+
static VALUE rbncurs_c_menu_driver(VALUE rb_menu, VALUE c)
|
316
|
+
{
|
317
|
+
MENU *menu = get_menu(rb_menu);
|
318
|
+
return INT2NUM(menu_driver(menu, NUM2INT(c)));
|
319
|
+
}
|
320
|
+
static VALUE rbncurs_m_menu_driver(VALUE dummy, VALUE rb_menu, VALUE c)
|
321
|
+
{ return rbncurs_c_menu_driver(rb_menu, c); }
|
322
|
+
|
323
|
+
|
324
|
+
/*
|
325
|
+
* Current menu item get/set functions - mitem_current(3X) man page
|
326
|
+
*/
|
327
|
+
static VALUE rbncurs_c_current_item(VALUE rb_menu)
|
328
|
+
{
|
329
|
+
MENU *menu = get_menu(rb_menu);
|
330
|
+
return wrap_item(current_item(menu));
|
331
|
+
}
|
332
|
+
static VALUE rbncurs_m_current_item(VALUE dummy, VALUE rb_menu)
|
333
|
+
{ return rbncurs_c_current_item(rb_menu); }
|
334
|
+
|
335
|
+
static VALUE rbncurs_c_set_current_item(VALUE rb_menu, VALUE rb_item)
|
336
|
+
{
|
337
|
+
MENU *menu = get_menu(rb_menu);
|
338
|
+
ITEM *item = get_item(rb_item);
|
339
|
+
return INT2NUM(set_current_item(menu, item));
|
340
|
+
}
|
341
|
+
static VALUE rbncurs_m_set_current_item(VALUE dummy, VALUE rb_menu, VALUE rb_item)
|
342
|
+
{ return rbncurs_c_set_current_item(rb_menu, rb_item); }
|
343
|
+
|
344
|
+
static VALUE rbncurs_c_top_row(VALUE rb_menu)
|
345
|
+
{
|
346
|
+
MENU *menu = get_menu(rb_menu);
|
347
|
+
return INT2NUM(top_row(menu));
|
348
|
+
}
|
349
|
+
static VALUE rbncurs_m_top_row(VALUE dummy, VALUE rb_menu)
|
350
|
+
{ return rbncurs_c_top_row(rb_menu); }
|
351
|
+
|
352
|
+
static VALUE rbncurs_c_set_top_row(VALUE rb_menu, VALUE n)
|
353
|
+
{
|
354
|
+
MENU *menu = get_menu(rb_menu);
|
355
|
+
return INT2NUM(set_top_row(menu, NUM2INT(n)));
|
356
|
+
}
|
357
|
+
static VALUE rbncurs_m_set_top_row(VALUE dummy, VALUE rb_menu, VALUE rb_item)
|
358
|
+
{ return rbncurs_c_set_top_row(rb_menu, rb_item); }
|
359
|
+
|
360
|
+
static VALUE rbncurs_c_item_index(VALUE rb_item)
|
361
|
+
{
|
362
|
+
ITEM *item = get_item(rb_item);
|
363
|
+
return INT2NUM(item_index(item));
|
364
|
+
}
|
365
|
+
static VALUE rbncurs_m_item_index(VALUE dummy, VALUE rb_item)
|
366
|
+
{ return rbncurs_c_item_index(rb_item); }
|
367
|
+
|
368
|
+
|
369
|
+
/*
|
370
|
+
* Item creation/destruction functions - mitem_new(3X) man page
|
371
|
+
*/
|
372
|
+
static VALUE rbncurs_m_new_item(VALUE dummy, VALUE name, VALUE description)
|
373
|
+
{ return wrap_item(new_item(STR2CSTR(name), STR2CSTR(description))); }
|
374
|
+
|
375
|
+
static VALUE rbncurs_c_free_item(VALUE rb_item)
|
376
|
+
{
|
377
|
+
VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
|
378
|
+
ITEM *item = get_item(rb_item);
|
379
|
+
VALUE item_address = INT2NUM((long)(item));
|
380
|
+
rb_funcall(items_hash, rb_intern("delete"), 1, item_address);
|
381
|
+
rb_iv_set(rb_item, "@destroyed", Qtrue);
|
382
|
+
return INT2NUM(free_item(item));
|
383
|
+
}
|
384
|
+
static VALUE rbncurs_m_free_item(VALUE dummy, VALUE rb_item)
|
385
|
+
{ return rbncurs_c_free_item(rb_item); }
|
386
|
+
|
387
|
+
|
388
|
+
/*
|
389
|
+
* Item-menu connection make/break functions - menu_items(3X) man page
|
390
|
+
*/
|
391
|
+
static VALUE rbncurs_c_set_menu_items(VALUE rb_menu, VALUE rb_item_array)
|
392
|
+
{
|
393
|
+
long n = rbncurs_array_length(rb_item_array);
|
394
|
+
/* If ncurses does not free memory used by the previous array of strings, */
|
395
|
+
/* we will have to do it now. */
|
396
|
+
ITEM **items = ALLOC_N(ITEM*, (n+1));
|
397
|
+
long i;
|
398
|
+
MENU *menu = NULL;
|
399
|
+
|
400
|
+
for (i=0; i<n; i++)
|
401
|
+
items[i] = get_item(rb_ary_entry(rb_item_array, i));
|
402
|
+
items[n] = NULL;
|
403
|
+
menu = get_menu(rb_menu);
|
404
|
+
return INT2NUM(set_menu_items(menu, items));
|
405
|
+
}
|
406
|
+
static VALUE rbncurs_m_set_menu_items(VALUE dummy, VALUE rb_menu, VALUE rb_item_array)
|
407
|
+
{ return rbncurs_c_set_menu_items(rb_menu, rb_item_array); }
|
408
|
+
|
409
|
+
static VALUE rbncurs_c_menu_items(VALUE rb_menu)
|
410
|
+
{
|
411
|
+
MENU *menu = get_menu(rb_menu);
|
412
|
+
ITEM **items = menu_items(menu);
|
413
|
+
VALUE arr = Qundef;
|
414
|
+
int i;
|
415
|
+
|
416
|
+
if (items == NULL)
|
417
|
+
rb_raise(rb_eRuntimeError, "Error retrieving menu items");
|
418
|
+
arr = rb_ary_new();
|
419
|
+
i=0;
|
420
|
+
while (items[i] != NULL)
|
421
|
+
rb_ary_push(arr, wrap_item(items[i++]));
|
422
|
+
return arr;
|
423
|
+
}
|
424
|
+
static VALUE rbncurs_m_menu_items(VALUE dummy, VALUE rb_menu)
|
425
|
+
{ return rbncurs_c_menu_items(rb_menu); }
|
426
|
+
|
427
|
+
static VALUE rbncurs_c_item_count(VALUE rb_menu)
|
428
|
+
{
|
429
|
+
MENU *menu = get_menu(rb_menu);
|
430
|
+
return INT2NUM(item_count(menu));
|
431
|
+
}
|
432
|
+
static VALUE rbncurs_m_item_count(VALUE dummy, VALUE rb_menu)
|
433
|
+
{ return rbncurs_c_item_count(rb_menu); }
|
434
|
+
|
435
|
+
|
436
|
+
/*
|
437
|
+
* Item/menu hook get/set functions - menu_hook(3X) man page
|
438
|
+
*/
|
439
|
+
static void item_init_hook(MENU *menu)
|
440
|
+
{
|
441
|
+
/* Find the Proc object associated with this menu */
|
442
|
+
VALUE proc = get_proc(menu, ITEM_INIT_HOOK);
|
443
|
+
|
444
|
+
if (proc != Qnil)
|
445
|
+
{
|
446
|
+
VALUE rb_menu = wrap_menu(menu);
|
447
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_menu);
|
448
|
+
}
|
449
|
+
}
|
450
|
+
static VALUE rbncurs_c_set_item_init(VALUE rb_menu, VALUE proc)
|
451
|
+
{
|
452
|
+
MENU *menu = NULL;
|
453
|
+
|
454
|
+
if (!rb_obj_is_kind_of(rb_menu, cMENU))
|
455
|
+
rb_raise(rb_eArgError, "arg1 must be a MENU object");
|
456
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
457
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
458
|
+
menu = get_menu(rb_menu);
|
459
|
+
reg_proc(menu, ITEM_INIT_HOOK, proc);
|
460
|
+
if (proc != Qnil)
|
461
|
+
return INT2NUM(set_item_init(menu, item_init_hook));
|
462
|
+
else
|
463
|
+
return INT2NUM(set_item_init(menu, NULL));
|
464
|
+
}
|
465
|
+
static VALUE rbncurs_m_set_item_init(VALUE dummy, VALUE rb_menu, VALUE proc)
|
466
|
+
{ return rbncurs_c_set_item_init(rb_menu, proc); }
|
467
|
+
|
468
|
+
static VALUE rbncurs_c_item_init(VALUE rb_menu)
|
469
|
+
{
|
470
|
+
MENU *menu = get_menu(rb_menu);
|
471
|
+
return get_proc(menu, ITEM_INIT_HOOK);
|
472
|
+
}
|
473
|
+
static VALUE rbncurs_m_item_init(VALUE dummy, VALUE rb_menu)
|
474
|
+
{ return rbncurs_c_item_init(rb_menu); }
|
475
|
+
|
476
|
+
static void item_term_hook(MENU *menu)
|
477
|
+
{
|
478
|
+
/* Find the Proc object associated with this menu */
|
479
|
+
VALUE proc = get_proc(menu, ITEM_TERM_HOOK);
|
480
|
+
|
481
|
+
if (proc != Qnil)
|
482
|
+
{
|
483
|
+
VALUE rb_menu = wrap_menu(menu);
|
484
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_menu);
|
485
|
+
}
|
486
|
+
}
|
487
|
+
static VALUE rbncurs_c_set_item_term(VALUE rb_menu, VALUE proc)
|
488
|
+
{
|
489
|
+
MENU *menu = NULL;
|
490
|
+
|
491
|
+
if (!rb_obj_is_kind_of(rb_menu, cMENU))
|
492
|
+
rb_raise(rb_eArgError, "arg1 must be a MENU object");
|
493
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
494
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
495
|
+
menu = get_menu(rb_menu);
|
496
|
+
reg_proc(menu, ITEM_TERM_HOOK, proc);
|
497
|
+
if (proc != Qnil)
|
498
|
+
return INT2NUM(set_item_term(menu, item_term_hook));
|
499
|
+
else
|
500
|
+
return INT2NUM(set_item_term(menu, NULL));
|
501
|
+
}
|
502
|
+
static VALUE rbncurs_m_set_item_term(VALUE dummy, VALUE rb_menu, VALUE proc)
|
503
|
+
{ return rbncurs_c_set_item_term(rb_menu, proc); }
|
504
|
+
|
505
|
+
static VALUE rbncurs_c_item_term(VALUE rb_menu)
|
506
|
+
{
|
507
|
+
MENU *menu = get_menu(rb_menu);
|
508
|
+
return get_proc(menu, ITEM_TERM_HOOK);
|
509
|
+
}
|
510
|
+
static VALUE rbncurs_m_item_term(VALUE dummy, VALUE rb_menu)
|
511
|
+
{ return rbncurs_c_item_term(rb_menu); }
|
512
|
+
|
513
|
+
static void menu_init_hook(MENU *menu)
|
514
|
+
{
|
515
|
+
/* Find the Proc object associated with this menu */
|
516
|
+
VALUE proc = get_proc(menu, MENU_INIT_HOOK);
|
517
|
+
|
518
|
+
if (proc != Qnil)
|
519
|
+
{
|
520
|
+
VALUE rb_menu = wrap_menu(menu);
|
521
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_menu);
|
522
|
+
}
|
523
|
+
}
|
524
|
+
static VALUE rbncurs_c_set_menu_init(VALUE rb_menu, VALUE proc) {
|
525
|
+
MENU *menu = NULL;
|
526
|
+
|
527
|
+
if (!rb_obj_is_kind_of(rb_menu, cMENU))
|
528
|
+
rb_raise(rb_eArgError, "arg1 must be a MENU object");
|
529
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
530
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
531
|
+
menu = get_menu(rb_menu);
|
532
|
+
reg_proc(menu, MENU_INIT_HOOK, proc);
|
533
|
+
if (proc != Qnil)
|
534
|
+
return INT2NUM(set_menu_init(menu, menu_init_hook));
|
535
|
+
else
|
536
|
+
return INT2NUM(set_menu_init(menu, NULL));
|
537
|
+
}
|
538
|
+
static VALUE rbncurs_m_set_menu_init(VALUE dummy, VALUE rb_menu, VALUE proc)
|
539
|
+
{ return rbncurs_c_set_menu_init(rb_menu, proc); }
|
540
|
+
|
541
|
+
static VALUE rbncurs_c_menu_init(VALUE rb_menu)
|
542
|
+
{
|
543
|
+
MENU *menu = get_menu(rb_menu);
|
544
|
+
return get_proc(menu, MENU_INIT_HOOK);
|
545
|
+
}
|
546
|
+
static VALUE rbncurs_m_menu_init(VALUE dummy, VALUE rb_menu)
|
547
|
+
{ return rbncurs_c_menu_init(rb_menu); }
|
548
|
+
|
549
|
+
static void menu_term_hook(MENU *menu)
|
550
|
+
{
|
551
|
+
/* Find the Proc object associated with this menu */
|
552
|
+
VALUE proc = get_proc(menu, MENU_TERM_HOOK);
|
553
|
+
|
554
|
+
if (proc != Qnil)
|
555
|
+
{
|
556
|
+
VALUE rb_menu = wrap_menu(menu);
|
557
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_menu);
|
558
|
+
}
|
559
|
+
}
|
560
|
+
static VALUE rbncurs_c_set_menu_term(VALUE rb_menu, VALUE proc)
|
561
|
+
{
|
562
|
+
MENU *menu = NULL;
|
563
|
+
|
564
|
+
if (!rb_obj_is_kind_of(rb_menu, cMENU))
|
565
|
+
rb_raise(rb_eArgError, "arg1 must be a MENU object");
|
566
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
567
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
568
|
+
menu = get_menu(rb_menu);
|
569
|
+
reg_proc(menu, MENU_TERM_HOOK, proc);
|
570
|
+
if (proc != Qnil)
|
571
|
+
return INT2NUM(set_menu_term(menu, menu_term_hook));
|
572
|
+
else
|
573
|
+
return INT2NUM(set_menu_term(menu, NULL));
|
574
|
+
}
|
575
|
+
static VALUE rbncurs_m_set_menu_term(VALUE dummy, VALUE rb_menu, VALUE proc)
|
576
|
+
{ return rbncurs_c_set_menu_term(rb_menu, proc); }
|
577
|
+
|
578
|
+
static VALUE rbncurs_c_menu_term(VALUE rb_menu)
|
579
|
+
{
|
580
|
+
MENU *menu = get_menu(rb_menu);
|
581
|
+
return get_proc(menu, MENU_TERM_HOOK);
|
582
|
+
}
|
583
|
+
static VALUE rbncurs_m_menu_term(VALUE dummy, VALUE rb_menu)
|
584
|
+
{ return rbncurs_c_menu_term(rb_menu); }
|
585
|
+
|
586
|
+
|
587
|
+
/*
|
588
|
+
* Item option get/set functions - mitem_opts(3X) man page
|
589
|
+
*/
|
590
|
+
static VALUE rbncurs_c_set_item_opts(VALUE rb_item, VALUE opts)
|
591
|
+
{
|
592
|
+
ITEM *item = get_item(rb_item);
|
593
|
+
return INT2NUM(set_item_opts(item, NUM2INT(opts)));
|
594
|
+
}
|
595
|
+
static VALUE rbncurs_m_set_item_opts(VALUE dummy, VALUE rb_item, VALUE opts)
|
596
|
+
{ return rbncurs_c_set_item_opts(rb_item, opts); }
|
597
|
+
|
598
|
+
static VALUE rbncurs_c_item_opts_on(VALUE rb_item, VALUE opts)
|
599
|
+
{
|
600
|
+
ITEM *item = get_item(rb_item);
|
601
|
+
return INT2NUM(item_opts_on(item, NUM2INT(opts)));
|
602
|
+
}
|
603
|
+
static VALUE rbncurs_m_item_opts_on(VALUE dummy, VALUE rb_item, VALUE opts)
|
604
|
+
{ return rbncurs_c_item_opts_on(rb_item, opts); }
|
605
|
+
|
606
|
+
static VALUE rbncurs_c_item_opts_off(VALUE rb_item, VALUE opts)
|
607
|
+
{
|
608
|
+
ITEM *item = get_item(rb_item);
|
609
|
+
return INT2NUM(item_opts_off(item, NUM2INT(opts)));
|
610
|
+
}
|
611
|
+
static VALUE rbncurs_m_item_opts_off(VALUE dummy, VALUE rb_item, VALUE opts)
|
612
|
+
{ return rbncurs_c_item_opts_off(rb_item, opts); }
|
613
|
+
|
614
|
+
static VALUE rbncurs_c_item_opts(VALUE rb_item)
|
615
|
+
{
|
616
|
+
ITEM *item = get_item(rb_item);
|
617
|
+
return INT2NUM(item_opts(item));
|
618
|
+
}
|
619
|
+
static VALUE rbncurs_m_item_opts(VALUE dummy, VALUE rb_item)
|
620
|
+
{ return rbncurs_c_item_opts(rb_item); }
|
621
|
+
|
622
|
+
|
623
|
+
/*
|
624
|
+
* Menu option get/set functions - menu_opts(3X) man page
|
625
|
+
*/
|
626
|
+
static VALUE rbncurs_c_set_menu_opts(VALUE rb_menu, VALUE opts)
|
627
|
+
{
|
628
|
+
MENU *menu = get_menu(rb_menu);
|
629
|
+
return INT2NUM(set_menu_opts(menu, NUM2INT(opts)));
|
630
|
+
}
|
631
|
+
static VALUE rbncurs_m_set_menu_opts(VALUE dummy, VALUE rb_menu, VALUE opts)
|
632
|
+
{ return rbncurs_c_set_menu_opts(rb_menu, opts); }
|
633
|
+
|
634
|
+
static VALUE rbncurs_c_menu_opts_on(VALUE rb_menu, VALUE opts)
|
635
|
+
{
|
636
|
+
MENU *menu = get_menu(rb_menu);
|
637
|
+
return INT2NUM(menu_opts_on(menu, NUM2INT(opts)));
|
638
|
+
}
|
639
|
+
static VALUE rbncurs_m_menu_opts_on(VALUE dummy, VALUE rb_menu, VALUE opts)
|
640
|
+
{ return rbncurs_c_menu_opts_on(rb_menu, opts); }
|
641
|
+
|
642
|
+
static VALUE rbncurs_c_menu_opts_off(VALUE rb_menu, VALUE opts)
|
643
|
+
{
|
644
|
+
MENU *menu = get_menu(rb_menu);
|
645
|
+
return INT2NUM(menu_opts_off(menu, NUM2INT(opts)));
|
646
|
+
}
|
647
|
+
static VALUE rbncurs_m_menu_opts_off(VALUE dummy, VALUE rb_menu, VALUE opts)
|
648
|
+
{ return rbncurs_c_menu_opts_off(rb_menu, opts); }
|
649
|
+
|
650
|
+
static VALUE rbncurs_c_menu_opts(VALUE rb_menu)
|
651
|
+
{
|
652
|
+
MENU *menu = get_menu(rb_menu);
|
653
|
+
return INT2NUM(menu_opts(menu));
|
654
|
+
}
|
655
|
+
static VALUE rbncurs_m_menu_opts(VALUE dummy, VALUE rb_menu)
|
656
|
+
{ return rbncurs_c_menu_opts(rb_menu); }
|
657
|
+
|
658
|
+
|
659
|
+
/*
|
660
|
+
* Printable menu request name handling functions - menu_requestname(3X) man page
|
661
|
+
*/
|
662
|
+
static VALUE rbncurs_c_menu_request_name(VALUE request)
|
663
|
+
{
|
664
|
+
return rb_str_new2(menu_request_name(NUM2INT(request)));
|
665
|
+
}
|
666
|
+
static VALUE rbncurs_m_menu_request_name(VALUE dummy, VALUE request)
|
667
|
+
{ return rbncurs_c_menu_request_name(request); }
|
668
|
+
|
669
|
+
static VALUE rbncurs_c_menu_request_by_name(VALUE name)
|
670
|
+
{
|
671
|
+
return INT2NUM(menu_request_by_name(STR2CSTR(name)));
|
672
|
+
}
|
673
|
+
static VALUE rbncurs_m_menu_request_by_name(VALUE dummy, VALUE name)
|
674
|
+
{ return rbncurs_c_menu_request_by_name(name); }
|
675
|
+
|
676
|
+
|
677
|
+
/*
|
678
|
+
* (Sub)window association make/break functions - menu_win(3X) man page
|
679
|
+
*/
|
680
|
+
static VALUE rbncurs_c_set_menu_win(VALUE rb_menu, VALUE rb_win)
|
681
|
+
{
|
682
|
+
MENU *menu = get_menu(rb_menu);
|
683
|
+
WINDOW *win = get_window(rb_win);
|
684
|
+
return INT2NUM(set_menu_win(menu, win));
|
685
|
+
}
|
686
|
+
static VALUE rbncurs_m_set_menu_win(VALUE dummy, VALUE rb_menu, VALUE rb_win)
|
687
|
+
{ return rbncurs_c_set_menu_win(rb_menu, rb_win); }
|
688
|
+
|
689
|
+
static VALUE rbncurs_c_menu_win(VALUE rb_menu)
|
690
|
+
{
|
691
|
+
MENU *menu = get_menu(rb_menu);
|
692
|
+
return wrap_window(menu_win(menu));
|
693
|
+
}
|
694
|
+
static VALUE rbncurs_m_menu_win(VALUE dummy, VALUE rb_menu)
|
695
|
+
{ return rbncurs_c_menu_win(rb_menu); }
|
696
|
+
|
697
|
+
static VALUE rbncurs_c_set_menu_sub(VALUE rb_menu, VALUE rb_sub)
|
698
|
+
{
|
699
|
+
MENU *menu = get_menu(rb_menu);
|
700
|
+
WINDOW *win = get_window(rb_sub);
|
701
|
+
return INT2NUM(set_menu_sub(menu, win));
|
702
|
+
}
|
703
|
+
static VALUE rbncurs_m_set_menu_sub(VALUE dummy, VALUE rb_menu, VALUE rb_sub)
|
704
|
+
{ return rbncurs_c_set_menu_sub(rb_menu, rb_sub); }
|
705
|
+
|
706
|
+
static VALUE rbncurs_c_menu_sub(VALUE rb_menu)
|
707
|
+
{
|
708
|
+
MENU *menu = get_menu(rb_menu);
|
709
|
+
return wrap_window(menu_sub(menu));
|
710
|
+
}
|
711
|
+
static VALUE rbncurs_m_menu_sub(VALUE dummy, VALUE rb_menu)
|
712
|
+
{ return rbncurs_c_menu_sub(rb_menu); }
|
713
|
+
|
714
|
+
static VALUE rbncurs_c_scale_menu(VALUE rb_menu, VALUE rows, VALUE columns)
|
715
|
+
{
|
716
|
+
MENU *menu = get_menu(rb_menu);
|
717
|
+
|
718
|
+
if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue ||
|
719
|
+
rb_obj_is_instance_of(columns, rb_cArray) != Qtrue)
|
720
|
+
{
|
721
|
+
rb_raise(rb_eArgError, "rows and columns arguments must be empty Arrays");
|
722
|
+
return Qnil;
|
723
|
+
}
|
724
|
+
else
|
725
|
+
{
|
726
|
+
int vals[2] = {0,0};
|
727
|
+
int result = scale_menu(menu, &vals[0],&vals[1]);
|
728
|
+
|
729
|
+
rb_ary_push(rows, INT2NUM(vals[0]));
|
730
|
+
rb_ary_push(columns, INT2NUM(vals[1]));
|
731
|
+
return INT2NUM(result);
|
732
|
+
}
|
733
|
+
}
|
734
|
+
static VALUE rbncurs_m_scale_menu(VALUE dummy, VALUE rb_menu, VALUE rows, VALUE columns)
|
735
|
+
{ return rbncurs_c_scale_menu(rb_menu, rows, columns); }
|
736
|
+
|
737
|
+
|
738
|
+
/*
|
739
|
+
* Menu cursor positioning functions - menu_cursor(3X) man page
|
740
|
+
*/
|
741
|
+
static VALUE rbncurs_c_pos_menu_cursor(VALUE rb_menu)
|
742
|
+
{
|
743
|
+
MENU *menu = get_menu(rb_menu);
|
744
|
+
return INT2NUM(pos_menu_cursor(menu));
|
745
|
+
}
|
746
|
+
static VALUE rbncurs_m_pos_menu_cursor(VALUE dummy, VALUE rb_menu)
|
747
|
+
{ return rbncurs_c_pos_menu_cursor(rb_menu); }
|
748
|
+
|
749
|
+
|
750
|
+
/*
|
751
|
+
* Item name/description retrieval functions - mitem_name(3X) man page
|
752
|
+
*/
|
753
|
+
static VALUE rbncurs_c_item_name(VALUE rb_item)
|
754
|
+
{
|
755
|
+
ITEM *item = get_item(rb_item);
|
756
|
+
return rb_str_new2(item_name(item));
|
757
|
+
}
|
758
|
+
static VALUE rbncurs_m_item_name(VALUE dummy, VALUE rb_item)
|
759
|
+
{ return rbncurs_c_item_name(rb_item); }
|
760
|
+
|
761
|
+
static VALUE rbncurs_c_item_description(VALUE rb_item)
|
762
|
+
{
|
763
|
+
ITEM *item = get_item(rb_item);
|
764
|
+
return rb_str_new2(item_description(item));
|
765
|
+
}
|
766
|
+
static VALUE rbncurs_m_item_description(VALUE dummy, VALUE rb_item)
|
767
|
+
{ return rbncurs_c_item_description(rb_item); }
|
768
|
+
|
769
|
+
|
770
|
+
/*
|
771
|
+
* Item value get/set functions - mitem_value(3X) man page
|
772
|
+
*/
|
773
|
+
static VALUE rbncurs_c_set_item_value(VALUE rb_item, VALUE value)
|
774
|
+
{
|
775
|
+
ITEM *item = get_item(rb_item);
|
776
|
+
return INT2NUM(set_item_value(item, RTEST(value)));
|
777
|
+
}
|
778
|
+
static VALUE rbncurs_m_set_item_value(VALUE dummy, VALUE rb_item, VALUE value)
|
779
|
+
{ return rbncurs_c_set_item_value(rb_item, value); }
|
780
|
+
|
781
|
+
static VALUE rbncurs_c_item_value(VALUE rb_item)
|
782
|
+
{
|
783
|
+
ITEM *item = get_item(rb_item);
|
784
|
+
return (item_value(item)) ? Qtrue: Qfalse;
|
785
|
+
}
|
786
|
+
static VALUE rbncurs_m_item_value(VALUE dummy, VALUE rb_item)
|
787
|
+
{ return rbncurs_c_item_value(rb_item); }
|
788
|
+
|
789
|
+
|
790
|
+
/*
|
791
|
+
* Item visibility retrieval function - mitem_visible(3X) man page
|
792
|
+
*/
|
793
|
+
static VALUE rbncurs_c_item_visible(VALUE rb_item)
|
794
|
+
{
|
795
|
+
ITEM *item = get_item(rb_item);
|
796
|
+
return (item_visible(item)) ? Qtrue: Qfalse;
|
797
|
+
}
|
798
|
+
static VALUE rbncurs_m_item_visible(VALUE dummy, VALUE rb_item)
|
799
|
+
{ return rbncurs_c_item_visible(rb_item); }
|
800
|
+
|
801
|
+
|
802
|
+
/*
|
803
|
+
* Menu attribute get/set functions - menu_attributes(3X) man page
|
804
|
+
*/
|
805
|
+
static VALUE rbncurs_c_set_menu_fore(VALUE rb_menu, VALUE attr)
|
806
|
+
{
|
807
|
+
MENU *menu = get_menu(rb_menu);
|
808
|
+
return INT2NUM(set_menu_fore(menu, NUM2ULONG(attr)));
|
809
|
+
}
|
810
|
+
static VALUE rbncurs_m_set_menu_fore(VALUE dummy, VALUE rb_menu, VALUE attr)
|
811
|
+
{ return rbncurs_c_set_menu_fore(rb_menu, attr); }
|
812
|
+
|
813
|
+
static VALUE rbncurs_c_menu_fore(VALUE rb_menu)
|
814
|
+
{
|
815
|
+
MENU *menu = get_menu(rb_menu);
|
816
|
+
return ULONG2NUM(menu_fore(menu));
|
817
|
+
}
|
818
|
+
static VALUE rbncurs_m_menu_fore(VALUE dummy, VALUE rb_menu)
|
819
|
+
{ return rbncurs_c_menu_fore(rb_menu); }
|
820
|
+
|
821
|
+
static VALUE rbncurs_c_set_menu_back(VALUE rb_menu, VALUE attr)
|
822
|
+
{
|
823
|
+
MENU *menu = get_menu(rb_menu);
|
824
|
+
return INT2NUM(set_menu_back(menu, NUM2ULONG(attr)));
|
825
|
+
}
|
826
|
+
static VALUE rbncurs_m_set_menu_back(VALUE dummy, VALUE rb_menu, VALUE attr)
|
827
|
+
{ return rbncurs_c_set_menu_back(rb_menu, attr); }
|
828
|
+
|
829
|
+
static VALUE rbncurs_c_menu_back(VALUE rb_menu)
|
830
|
+
{
|
831
|
+
MENU *menu = get_menu(rb_menu);
|
832
|
+
return ULONG2NUM(menu_back(menu));
|
833
|
+
}
|
834
|
+
static VALUE rbncurs_m_menu_back(VALUE dummy, VALUE rb_menu)
|
835
|
+
{ return rbncurs_c_menu_back(rb_menu); }
|
836
|
+
|
837
|
+
static VALUE rbncurs_c_set_menu_grey(VALUE rb_menu, VALUE attr)
|
838
|
+
{
|
839
|
+
MENU *menu = get_menu(rb_menu);
|
840
|
+
return INT2NUM(set_menu_grey(menu, NUM2ULONG(attr)));
|
841
|
+
}
|
842
|
+
static VALUE rbncurs_m_set_menu_grey(VALUE dummy, VALUE rb_menu, VALUE attr)
|
843
|
+
{ return rbncurs_c_set_menu_grey(rb_menu, attr); }
|
844
|
+
|
845
|
+
static VALUE rbncurs_c_menu_grey(VALUE rb_menu)
|
846
|
+
{
|
847
|
+
MENU *menu = get_menu(rb_menu);
|
848
|
+
return ULONG2NUM(menu_grey(menu));
|
849
|
+
}
|
850
|
+
static VALUE rbncurs_m_menu_grey(VALUE dummy, VALUE rb_menu)
|
851
|
+
{ return rbncurs_c_menu_grey(rb_menu); }
|
852
|
+
|
853
|
+
static VALUE rbncurs_c_set_menu_pad(VALUE rb_menu, VALUE pad)
|
854
|
+
{
|
855
|
+
MENU *menu = get_menu(rb_menu);
|
856
|
+
return INT2NUM(set_menu_pad(menu, NUM2INT(pad)));
|
857
|
+
}
|
858
|
+
static VALUE rbncurs_m_set_menu_pad(VALUE dummy, VALUE rb_menu, VALUE pad)
|
859
|
+
{ return rbncurs_c_set_menu_pad(rb_menu, pad); }
|
860
|
+
|
861
|
+
static VALUE rbncurs_c_menu_pad(VALUE rb_menu)
|
862
|
+
{
|
863
|
+
MENU *menu = get_menu(rb_menu);
|
864
|
+
return INT2NUM(menu_pad(menu));
|
865
|
+
}
|
866
|
+
static VALUE rbncurs_m_menu_pad(VALUE dummy, VALUE rb_menu)
|
867
|
+
{ return rbncurs_c_menu_pad(rb_menu); }
|
868
|
+
|
869
|
+
|
870
|
+
/*
|
871
|
+
* Menu format get/set functions - menu_format(3X) man page
|
872
|
+
*/
|
873
|
+
static VALUE rbncurs_c_set_menu_format(VALUE rb_menu, VALUE rows, VALUE cols)
|
874
|
+
{
|
875
|
+
MENU *menu = get_menu(rb_menu);
|
876
|
+
return INT2NUM(set_menu_format(menu, NUM2INT(rows), NUM2INT(cols)));
|
877
|
+
}
|
878
|
+
static VALUE rbncurs_m_set_menu_format(VALUE dummy, VALUE rb_menu, VALUE rows, VALUE cols)
|
879
|
+
{ return rbncurs_c_set_menu_format(rb_menu, rows, cols); }
|
880
|
+
|
881
|
+
static VALUE rbncurs_c_menu_format(VALUE rb_menu, VALUE rows, VALUE cols)
|
882
|
+
{
|
883
|
+
if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue ||
|
884
|
+
rb_obj_is_instance_of(cols, rb_cArray) != Qtrue)
|
885
|
+
{
|
886
|
+
rb_raise(rb_eArgError, "rows and cols arguments must be empty Arrays");
|
887
|
+
return Qnil;
|
888
|
+
}
|
889
|
+
else
|
890
|
+
{
|
891
|
+
MENU *menu = get_menu(rb_menu);
|
892
|
+
int vals[2] = {0,0};
|
893
|
+
|
894
|
+
menu_format(menu, &vals[0], &vals[1]);
|
895
|
+
rb_ary_push(rows, INT2NUM(vals[0]));
|
896
|
+
rb_ary_push(cols, INT2NUM(vals[1]));
|
897
|
+
return Qnil;
|
898
|
+
}
|
899
|
+
}
|
900
|
+
static VALUE rbncurs_m_menu_format(VALUE dummy, VALUE rb_menu, VALUE rows, VALUE cols)
|
901
|
+
{ return rbncurs_c_menu_format(rb_menu, rows, cols); }
|
902
|
+
|
903
|
+
|
904
|
+
/*
|
905
|
+
* Menu mark get/set functions - menu_mark(3X) man page
|
906
|
+
*/
|
907
|
+
static VALUE rbncurs_c_set_menu_mark(VALUE rb_menu, VALUE value)
|
908
|
+
{
|
909
|
+
MENU *menu = get_menu(rb_menu);
|
910
|
+
return INT2NUM(set_menu_mark(menu, STR2CSTR(value)));
|
911
|
+
}
|
912
|
+
static VALUE rbncurs_m_set_menu_mark(VALUE dummy, VALUE rb_field, VALUE value)
|
913
|
+
{ return rbncurs_c_set_menu_mark(rb_field, value); }
|
914
|
+
|
915
|
+
static VALUE rbncurs_c_menu_mark(VALUE rb_menu)
|
916
|
+
{
|
917
|
+
MENU *menu = get_menu(rb_menu);
|
918
|
+
return rb_str_new2(menu_mark(menu));
|
919
|
+
}
|
920
|
+
static VALUE rbncurs_m_menu_mark(VALUE dummy, VALUE rb_menu)
|
921
|
+
{ return rbncurs_c_menu_mark(rb_menu); }
|
922
|
+
|
923
|
+
|
924
|
+
/*
|
925
|
+
* Menu pattern get/set functions - menu_pattern(3X) man page
|
926
|
+
*/
|
927
|
+
static VALUE rbncurs_c_set_menu_pattern(VALUE rb_menu, VALUE pattern)
|
928
|
+
{
|
929
|
+
MENU *menu = get_menu(rb_menu);
|
930
|
+
return INT2NUM(set_menu_pattern(menu, STR2CSTR(pattern)));
|
931
|
+
}
|
932
|
+
static VALUE rbncurs_m_set_menu_pattern(VALUE dummy, VALUE rb_menu, VALUE pattern)
|
933
|
+
{ return rbncurs_c_set_menu_pattern(rb_menu, pattern); }
|
934
|
+
|
935
|
+
static VALUE rbncurs_c_menu_pattern(VALUE rb_menu)
|
936
|
+
{
|
937
|
+
MENU *menu = get_menu(rb_menu);
|
938
|
+
return rb_str_new2(menu_pattern(menu));
|
939
|
+
}
|
940
|
+
static VALUE rbncurs_m_menu_pattern(VALUE dummy, VALUE rb_menu)
|
941
|
+
{ return rbncurs_c_menu_pattern(rb_menu); }
|
942
|
+
|
943
|
+
|
944
|
+
/*
|
945
|
+
* Menu spacing get/set functions - menu_spacing(3X) man page
|
946
|
+
*/
|
947
|
+
static VALUE rbncurs_c_set_menu_spacing(VALUE rb_menu, VALUE spc_description,
|
948
|
+
VALUE spc_rows, VALUE spc_cols)
|
949
|
+
{
|
950
|
+
MENU *menu = get_menu(rb_menu);
|
951
|
+
return INT2NUM(set_menu_spacing(menu, NUM2INT(spc_description),
|
952
|
+
NUM2INT(spc_rows), NUM2INT(spc_cols)));
|
953
|
+
}
|
954
|
+
static VALUE rbncurs_m_set_menu_spacing(VALUE dummy, VALUE rb_menu, VALUE spc_description,
|
955
|
+
VALUE spc_rows, VALUE spc_cols)
|
956
|
+
{ return rbncurs_c_set_menu_spacing(rb_menu, spc_description, spc_rows, spc_cols); }
|
957
|
+
|
958
|
+
static VALUE rbncurs_c_menu_spacing(VALUE rb_menu, VALUE spc_description,
|
959
|
+
VALUE spc_rows, VALUE spc_cols)
|
960
|
+
{
|
961
|
+
if (rb_obj_is_instance_of(spc_description, rb_cArray) != Qtrue ||
|
962
|
+
rb_obj_is_instance_of(spc_rows, rb_cArray) != Qtrue ||
|
963
|
+
rb_obj_is_instance_of(spc_cols, rb_cArray) != Qtrue)
|
964
|
+
{
|
965
|
+
rb_raise(rb_eArgError, "spc_description, spc_rows, and spc_cols arguments must be empty Arrays");
|
966
|
+
return Qnil;
|
967
|
+
}
|
968
|
+
else
|
969
|
+
{
|
970
|
+
MENU *menu = get_menu(rb_menu);
|
971
|
+
int vals[3] = {0,0,0};
|
972
|
+
|
973
|
+
int result = menu_spacing(menu, &vals[0], &vals[1], &vals[2]);
|
974
|
+
rb_ary_push(spc_description, INT2NUM(vals[0]));
|
975
|
+
rb_ary_push(spc_rows, INT2NUM(vals[1]));
|
976
|
+
rb_ary_push(spc_cols, INT2NUM(vals[2]));
|
977
|
+
return INT2NUM(result);
|
978
|
+
}
|
979
|
+
}
|
980
|
+
static VALUE rbncurs_m_menu_spacing(VALUE dummy, VALUE rb_menu, VALUE spc_description,
|
981
|
+
VALUE spc_rows, VALUE spc_cols)
|
982
|
+
{ return rbncurs_c_menu_spacing(rb_menu, spc_description, spc_rows, spc_cols); }
|
983
|
+
|
984
|
+
|
985
|
+
/*
|
986
|
+
* Menu initialization function
|
987
|
+
*/
|
988
|
+
void init_menu(void)
|
989
|
+
{
|
990
|
+
mMenu = rb_define_module_under(mNcurses, "Menu");
|
991
|
+
|
992
|
+
MENU_SNG_FUNC(current_item, 1);
|
993
|
+
MENU_SNG_FUNC(free_item, 1);
|
994
|
+
MENU_SNG_FUNC(free_menu, 1);
|
995
|
+
MENU_SNG_FUNC(item_count, 1);
|
996
|
+
MENU_SNG_FUNC(item_description, 1);
|
997
|
+
MENU_SNG_FUNC(item_index, 1);
|
998
|
+
MENU_SNG_FUNC(item_init, 1);
|
999
|
+
MENU_SNG_FUNC(item_name, 1);
|
1000
|
+
MENU_SNG_FUNC(item_opts, 1);
|
1001
|
+
MENU_SNG_FUNC(item_opts_off, 2);
|
1002
|
+
MENU_SNG_FUNC(item_opts_on, 2);
|
1003
|
+
MENU_SNG_FUNC(item_term, 1);
|
1004
|
+
/* MENU_SNG_FUNC(item_userptr, 1); */
|
1005
|
+
MENU_SNG_FUNC(item_value, 1);
|
1006
|
+
MENU_SNG_FUNC(item_visible, 1);
|
1007
|
+
MENU_SNG_FUNC(menu_back, 1);
|
1008
|
+
MENU_SNG_FUNC(menu_driver, 2);
|
1009
|
+
MENU_SNG_FUNC(menu_fore, 1);
|
1010
|
+
MENU_SNG_FUNC(menu_format, 3);
|
1011
|
+
MENU_SNG_FUNC(menu_grey, 1);
|
1012
|
+
MENU_SNG_FUNC(menu_init, 1);
|
1013
|
+
MENU_SNG_FUNC(menu_items, 1);
|
1014
|
+
MENU_SNG_FUNC(menu_mark, 1);
|
1015
|
+
MENU_SNG_FUNC(menu_opts, 1);
|
1016
|
+
MENU_SNG_FUNC(menu_opts_off, 2);
|
1017
|
+
MENU_SNG_FUNC(menu_opts_on, 2);
|
1018
|
+
MENU_SNG_FUNC(menu_pad, 1);
|
1019
|
+
MENU_SNG_FUNC(menu_pattern, 1);
|
1020
|
+
MENU_SNG_FUNC(menu_request_by_name, 1);
|
1021
|
+
MENU_SNG_FUNC(menu_request_name, 1);
|
1022
|
+
MENU_SNG_FUNC(menu_sub, 1);
|
1023
|
+
MENU_SNG_FUNC(menu_spacing, 4);
|
1024
|
+
MENU_SNG_FUNC(menu_term, 1);
|
1025
|
+
/* MENU_SNG_FUNC(menu_userptr, 1); */
|
1026
|
+
MENU_SNG_FUNC(menu_win, 1);
|
1027
|
+
MENU_SNG_FUNC(new_item, 2);
|
1028
|
+
MENU_SNG_FUNC(new_menu, 1);
|
1029
|
+
MENU_SNG_FUNC(pos_menu_cursor, 1);
|
1030
|
+
MENU_SNG_FUNC(post_menu, 1);
|
1031
|
+
MENU_SNG_FUNC(scale_menu, 3);
|
1032
|
+
MENU_SNG_FUNC(set_current_item, 2);
|
1033
|
+
MENU_SNG_FUNC(set_item_init, 2);
|
1034
|
+
MENU_SNG_FUNC(set_item_opts, 2);
|
1035
|
+
MENU_SNG_FUNC(set_item_term, 2);
|
1036
|
+
/* MENU_SNG_FUNC(set_item_userptr, 2); */
|
1037
|
+
MENU_SNG_FUNC(set_item_value, 2);
|
1038
|
+
MENU_SNG_FUNC(set_menu_back, 2);
|
1039
|
+
MENU_SNG_FUNC(set_menu_fore, 2);
|
1040
|
+
MENU_SNG_FUNC(set_menu_format, 3);
|
1041
|
+
MENU_SNG_FUNC(set_menu_grey, 2);
|
1042
|
+
MENU_SNG_FUNC(set_menu_init, 2);
|
1043
|
+
MENU_SNG_FUNC(set_menu_items, 2);
|
1044
|
+
MENU_SNG_FUNC(set_menu_mark, 2);
|
1045
|
+
MENU_SNG_FUNC(set_menu_opts, 2);
|
1046
|
+
MENU_SNG_FUNC(set_menu_pad, 2);
|
1047
|
+
MENU_SNG_FUNC(set_menu_pattern, 2);
|
1048
|
+
MENU_SNG_FUNC(set_menu_sub, 2);
|
1049
|
+
MENU_SNG_FUNC(set_menu_spacing, 4);
|
1050
|
+
MENU_SNG_FUNC(set_menu_term, 2);
|
1051
|
+
/* MENU_SNG_FUNC(set_menu_userptr, 2); */
|
1052
|
+
MENU_SNG_FUNC(set_menu_win, 2);
|
1053
|
+
MENU_SNG_FUNC(set_top_row, 2);
|
1054
|
+
MENU_SNG_FUNC(top_row, 1);
|
1055
|
+
MENU_SNG_FUNC(unpost_menu, 1);
|
1056
|
+
|
1057
|
+
init_menu_err_codes();
|
1058
|
+
init_menu_req_constants();
|
1059
|
+
init_menu_opts_constants();
|
1060
|
+
init_item_opts_constants();
|
1061
|
+
|
1062
|
+
/* Hashes to store registered blocks (Proc) */
|
1063
|
+
{
|
1064
|
+
VALUE hashes = rb_iv_set(mMenu, "@proc_hashes", rb_ary_new());
|
1065
|
+
int i;
|
1066
|
+
|
1067
|
+
for (i = 0; i < PROC_HASHES_COUNT; i++)
|
1068
|
+
rb_ary_push(hashes, rb_hash_new());
|
1069
|
+
}
|
1070
|
+
|
1071
|
+
/* Menus */
|
1072
|
+
rb_iv_set(mMenu, "@menus_hash", rb_hash_new());
|
1073
|
+
cMENU = rb_define_class_under(mMenu, "MENU", rb_cObject);
|
1074
|
+
rb_define_singleton_method(cMENU, "new", (&rbncurs_m_new_menu), 1);
|
1075
|
+
|
1076
|
+
RB_CLASS_METH(cMENU, NULL, current_item, 0);
|
1077
|
+
RB_CLASS_METH(cMENU, "free", free_menu, 0);
|
1078
|
+
RB_CLASS_METH(cMENU, NULL, item_count, 0);
|
1079
|
+
RB_CLASS_METH(cMENU, NULL, item_init, 0);
|
1080
|
+
RB_CLASS_METH(cMENU, NULL, item_term, 0);
|
1081
|
+
RB_CLASS_METH(cMENU, "back", menu_back, 0);
|
1082
|
+
RB_CLASS_METH(cMENU, "driver", menu_driver, 1);
|
1083
|
+
RB_CLASS_METH(cMENU, "fore", menu_fore, 0);
|
1084
|
+
RB_CLASS_METH(cMENU, "format", menu_format, 2);
|
1085
|
+
RB_CLASS_METH(cMENU, "grey", menu_grey, 0);
|
1086
|
+
RB_CLASS_METH(cMENU, "init", menu_init, 0);
|
1087
|
+
RB_CLASS_METH(cMENU, "items", menu_items, 0);
|
1088
|
+
RB_CLASS_METH(cMENU, "mark", menu_mark, 0);
|
1089
|
+
RB_CLASS_METH(cMENU, "opts", menu_opts, 0);
|
1090
|
+
RB_CLASS_METH(cMENU, "opts_off", menu_opts_off, 1);
|
1091
|
+
RB_CLASS_METH(cMENU, "opts_on", menu_opts_on, 1);
|
1092
|
+
RB_CLASS_METH(cMENU, "pad", menu_pad, 0);
|
1093
|
+
RB_CLASS_METH(cMENU, "pattern", menu_pattern, 0);
|
1094
|
+
RB_CLASS_METH(cMENU, "sub", menu_sub, 0);
|
1095
|
+
RB_CLASS_METH(cMENU, "spacing", menu_spacing, 3);
|
1096
|
+
RB_CLASS_METH(cMENU, "term", menu_term, 0);
|
1097
|
+
/* RB_CLASS_METH(cMENU, "userptr", menu_userptr, 0); */
|
1098
|
+
RB_CLASS_METH(cMENU, "win", menu_win, 0);
|
1099
|
+
RB_CLASS_METH(cMENU, "pos_cursor", pos_menu_cursor, 0);
|
1100
|
+
RB_CLASS_METH(cMENU, "post", post_menu, 0);
|
1101
|
+
RB_CLASS_METH(cMENU, "scale", scale_menu, 2);
|
1102
|
+
RB_CLASS_METH(cMENU, "current_item=", set_current_item, 1);
|
1103
|
+
RB_CLASS_METH(cMENU, "item_init=", set_item_init, 1);
|
1104
|
+
RB_CLASS_METH(cMENU, "item_term=", set_item_term, 1);
|
1105
|
+
RB_CLASS_METH(cMENU, "back=", set_menu_back, 1);
|
1106
|
+
RB_CLASS_METH(cMENU, "fore=", set_menu_fore, 1);
|
1107
|
+
RB_CLASS_METH(cMENU, "set_format", set_menu_format, 2);
|
1108
|
+
RB_CLASS_METH(cMENU, "grey=", set_menu_grey, 1);
|
1109
|
+
RB_CLASS_METH(cMENU, "init=", set_menu_init, 1);
|
1110
|
+
RB_CLASS_METH(cMENU, "items=", set_menu_items, 1);
|
1111
|
+
RB_CLASS_METH(cMENU, "mark=", set_menu_mark, 1);
|
1112
|
+
RB_CLASS_METH(cMENU, "opts=", set_menu_opts, 1);
|
1113
|
+
RB_CLASS_METH(cMENU, "pad=", set_menu_pad, 1);
|
1114
|
+
RB_CLASS_METH(cMENU, "pattern=", set_menu_pattern, 1);
|
1115
|
+
RB_CLASS_METH(cMENU, "sub=", set_menu_sub, 1);
|
1116
|
+
RB_CLASS_METH(cMENU, "set_spacing", set_menu_spacing, 3);
|
1117
|
+
RB_CLASS_METH(cMENU, "term=", set_menu_term, 1);
|
1118
|
+
/* RB_CLASS_METH(cMENU, "userptr=", set_menu_userptr, 1); */
|
1119
|
+
RB_CLASS_METH(cMENU, "win=", set_menu_win, 1);
|
1120
|
+
RB_CLASS_METH(cMENU, "top_row=", set_top_row, 1);
|
1121
|
+
RB_CLASS_METH(cMENU, NULL, top_row, 0);
|
1122
|
+
RB_CLASS_METH(cMENU, "unpost", unpost_menu, 0);
|
1123
|
+
|
1124
|
+
/* Items */
|
1125
|
+
rb_iv_set(mMenu, "@items_hash", rb_hash_new());
|
1126
|
+
cITEM = rb_define_class_under(mMenu, "ITEM", rb_cObject);
|
1127
|
+
rb_define_singleton_method(cITEM, "new", (&rbncurs_m_new_item), 2);
|
1128
|
+
|
1129
|
+
RB_CLASS_METH(cITEM, "free", free_item, 0);
|
1130
|
+
RB_CLASS_METH(cITEM, "description", item_description, 0);
|
1131
|
+
RB_CLASS_METH(cITEM, "index", item_index, 0);
|
1132
|
+
RB_CLASS_METH(cITEM, "name", item_name, 0);
|
1133
|
+
RB_CLASS_METH(cITEM, "opts", item_opts, 0);
|
1134
|
+
RB_CLASS_METH(cITEM, "opts_off", item_opts_off, 1);
|
1135
|
+
RB_CLASS_METH(cITEM, "opts_on", item_opts_on, 1);
|
1136
|
+
/* RB_CLASS_METH(cITEM, "userptr", item_userptr, 0); */
|
1137
|
+
RB_CLASS_METH(cITEM, "value", item_value, 0);
|
1138
|
+
RB_CLASS_METH(cITEM, "visible?", item_visible, 0);
|
1139
|
+
RB_CLASS_METH(cITEM, "opts=", set_item_opts, 1);
|
1140
|
+
/* RB_CLASS_METH(cITEM, "userptr=", set_item_userptr, 1); */
|
1141
|
+
RB_CLASS_METH(cITEM, "value=", set_item_value, 1);
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
#endif
|