ncurses-ruby 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,61 @@
|
|
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
|
+
* 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
|
+
*/
|
22
|
+
|
23
|
+
#if !defined(FORM_HH) && defined(HAVE_FORM_H)
|
24
|
+
#define FORM_HH
|
25
|
+
|
26
|
+
#include <form.h>
|
27
|
+
#include <ruby.h>
|
28
|
+
|
29
|
+
extern VALUE mForm;
|
30
|
+
extern VALUE cFIELD;
|
31
|
+
extern VALUE cFIELDTYPE;
|
32
|
+
extern VALUE cFORM;
|
33
|
+
/*extern VALUE cPAGE;*/
|
34
|
+
|
35
|
+
typedef struct {
|
36
|
+
bool (* field_check)(FIELD *,const void *);
|
37
|
+
FIELDTYPE* fieldtype;
|
38
|
+
} FLDCHKFUNC;
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
#define FORM_DEF_CONST(name) \
|
43
|
+
rb_define_const(mForm, #name, INT2NUM(name));
|
44
|
+
|
45
|
+
#define FORM_SNG_FUNC(name, nargs) \
|
46
|
+
rb_define_singleton_method(mForm, \
|
47
|
+
#name, \
|
48
|
+
&rbncurs_m_ ## name, \
|
49
|
+
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); \
|
54
|
+
|
55
|
+
void init_req_constants();
|
56
|
+
void init_just_constants();
|
57
|
+
void init_opts_constants();
|
58
|
+
|
59
|
+
void init_form(void);
|
60
|
+
|
61
|
+
#endif
|
@@ -0,0 +1,1141 @@
|
|
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
|
+
* This module is free software; you can redistribute it and/or
|
9
|
+
* modify it under the terms of the GNU Lesser General Public
|
10
|
+
* License as published by the Free Software Foundation; either
|
11
|
+
* version 2 of the License, or (at your option) any later version.
|
12
|
+
*
|
13
|
+
* This module is distributed in the hope that it will be useful,
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
* Lesser General Public License for more details.
|
17
|
+
*
|
18
|
+
* You should have received a copy of the GNU Lesser General Public
|
19
|
+
* License along with this module; if not, write to the Free Software
|
20
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
*
|
22
|
+
*/
|
23
|
+
|
24
|
+
#ifdef HAVE_MENU_H
|
25
|
+
|
26
|
+
#include "menu_wrap.h"
|
27
|
+
#include "ncurses_wrap.h"
|
28
|
+
|
29
|
+
VALUE mMenu;
|
30
|
+
VALUE cITEM;
|
31
|
+
VALUE cMENU;
|
32
|
+
|
33
|
+
void init_menu_err_codes(void)
|
34
|
+
{
|
35
|
+
/* The routine succeeded. */
|
36
|
+
MENU_DEF_CONST(E_OK);
|
37
|
+
/* System error occurred (see errno). */
|
38
|
+
MENU_DEF_CONST(E_SYSTEM_ERROR);
|
39
|
+
/* Routine detected an incorrect or out-of-range argument. */
|
40
|
+
MENU_DEF_CONST(E_BAD_ARGUMENT);
|
41
|
+
/* The menu is already posted. */
|
42
|
+
MENU_DEF_CONST(E_POSTED);
|
43
|
+
/* Routine was called from an initialization or termination function. */
|
44
|
+
MENU_DEF_CONST(E_BAD_STATE);
|
45
|
+
/* Menu is too large for its window. */
|
46
|
+
MENU_DEF_CONST(E_NO_ROOM);
|
47
|
+
/* The menu has not been posted. */
|
48
|
+
MENU_DEF_CONST(E_NOT_POSTED);
|
49
|
+
/* The menu driver code saw an unknown request code. */
|
50
|
+
MENU_DEF_CONST(E_UNKNOWN_COMMAND);
|
51
|
+
/* Character failed to match. */
|
52
|
+
MENU_DEF_CONST(E_NO_MATCH);
|
53
|
+
/* The designated item cannot be selected. */
|
54
|
+
MENU_DEF_CONST(E_NOT_SELECTABLE);
|
55
|
+
/* No items are connected to the menu. */
|
56
|
+
MENU_DEF_CONST(E_NOT_CONNECTED);
|
57
|
+
/* The menu driver could not process the request.} */
|
58
|
+
MENU_DEF_CONST(E_REQUEST_DENIED);
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
/*
|
63
|
+
* Menu driver request characters - menu_driver(3x) man page
|
64
|
+
*/
|
65
|
+
void init_menu_req_constants(void)
|
66
|
+
{
|
67
|
+
/* Move left to an item. */
|
68
|
+
MENU_DEF_CONST(REQ_LEFT_ITEM);
|
69
|
+
/* Move right to an item. */
|
70
|
+
MENU_DEF_CONST(REQ_RIGHT_ITEM);
|
71
|
+
/* Move up to an item. */
|
72
|
+
MENU_DEF_CONST(REQ_UP_ITEM);
|
73
|
+
/* Move down to an item. */
|
74
|
+
MENU_DEF_CONST(REQ_DOWN_ITEM);
|
75
|
+
/* Scroll up a line. */
|
76
|
+
MENU_DEF_CONST(REQ_SCR_ULINE);
|
77
|
+
/* Scroll down a line. */
|
78
|
+
MENU_DEF_CONST(REQ_SCR_DLINE);
|
79
|
+
/* Scroll up a page. */
|
80
|
+
MENU_DEF_CONST(REQ_SCR_UPAGE);
|
81
|
+
/* Scroll down a page. */
|
82
|
+
MENU_DEF_CONST(REQ_SCR_DPAGE);
|
83
|
+
/* Move to the first item. */
|
84
|
+
MENU_DEF_CONST(REQ_FIRST_ITEM);
|
85
|
+
/* Move to the last item. */
|
86
|
+
MENU_DEF_CONST(REQ_LAST_ITEM);
|
87
|
+
/* Move to the next item. */
|
88
|
+
MENU_DEF_CONST(REQ_NEXT_ITEM);
|
89
|
+
/* Move to the previous item. */
|
90
|
+
MENU_DEF_CONST(REQ_PREV_ITEM);
|
91
|
+
/* Select/deselect an item. */
|
92
|
+
MENU_DEF_CONST(REQ_TOGGLE_ITEM);
|
93
|
+
/* Clear the menu pattern buffer. */
|
94
|
+
MENU_DEF_CONST(REQ_CLEAR_PATTERN);
|
95
|
+
/* Delete the previous character from the pattern buffer. */
|
96
|
+
MENU_DEF_CONST(REQ_BACK_PATTERN);
|
97
|
+
/* Move to the next item matching the pattern match. */
|
98
|
+
MENU_DEF_CONST(REQ_NEXT_MATCH);
|
99
|
+
/* Move to the previous item matching the pattern match. */
|
100
|
+
MENU_DEF_CONST(REQ_PREV_MATCH);
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
/*
|
105
|
+
* Item options - mitem_opts(3x) man page
|
106
|
+
*/
|
107
|
+
void init_item_opts_constants(void)
|
108
|
+
{
|
109
|
+
/* Item may be selected during menu processing. */
|
110
|
+
MENU_DEF_CONST(O_SELECTABLE);
|
111
|
+
}
|
112
|
+
|
113
|
+
|
114
|
+
/*
|
115
|
+
* Menu options - menu_opts(3x) man page
|
116
|
+
*/
|
117
|
+
void init_menu_opts_constants(void)
|
118
|
+
{
|
119
|
+
/* Only one item can be selected for this menu. */
|
120
|
+
MENU_DEF_CONST(O_ONEVALUE);
|
121
|
+
/* Display the item descriptions when the menu is posted. */
|
122
|
+
MENU_DEF_CONST(O_SHOWDESC);
|
123
|
+
/* Display the menu in row-major order. */
|
124
|
+
MENU_DEF_CONST(O_ROWMAJOR);
|
125
|
+
/* Ignore the case when pattern-matching. */
|
126
|
+
MENU_DEF_CONST(O_IGNORECASE);
|
127
|
+
/* Move the cursor to within the item name while pattern-matching. */
|
128
|
+
MENU_DEF_CONST(O_SHOWMATCH);
|
129
|
+
/* Don’t wrap around next-item and previous-item, requests to the other end of the menu. */
|
130
|
+
MENU_DEF_CONST(O_NONCYCLIC);
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
/*
|
135
|
+
* ITEM wrapper
|
136
|
+
*/
|
137
|
+
static VALUE wrap_item(ITEM *item)
|
138
|
+
{
|
139
|
+
if (item == 0) return Qnil;
|
140
|
+
{
|
141
|
+
VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
|
142
|
+
VALUE item_address = INT2NUM((long)(item));
|
143
|
+
VALUE rb_item = rb_hash_aref(items_hash, item_address);
|
144
|
+
|
145
|
+
if (rb_item == Qnil)
|
146
|
+
{
|
147
|
+
rb_item = Data_Wrap_Struct(cITEM, 0, 0, item);
|
148
|
+
rb_iv_set(rb_item, "@destroyed", Qfalse);
|
149
|
+
rb_hash_aset(items_hash, item_address, rb_item);
|
150
|
+
}
|
151
|
+
return rb_item;
|
152
|
+
}
|
153
|
+
}
|
154
|
+
static ITEM *get_item(VALUE rb_item)
|
155
|
+
{
|
156
|
+
ITEM *item;
|
157
|
+
|
158
|
+
if (rb_item == Qnil) return 0;
|
159
|
+
if (rb_iv_get(rb_item, "@destroyed") == Qtrue)
|
160
|
+
{
|
161
|
+
rb_raise(rb_eRuntimeError, "Attempt to access a destroyed item");
|
162
|
+
return 0;
|
163
|
+
}
|
164
|
+
Data_Get_Struct(rb_item, ITEM, item);
|
165
|
+
return item;
|
166
|
+
}
|
167
|
+
|
168
|
+
|
169
|
+
/*
|
170
|
+
* MENU wrapper
|
171
|
+
*/
|
172
|
+
static VALUE wrap_menu(MENU *menu)
|
173
|
+
{
|
174
|
+
if (menu == 0) return Qnil;
|
175
|
+
{
|
176
|
+
VALUE menus_hash = rb_iv_get(mMenu, "@menus_hash");
|
177
|
+
VALUE menu_address = INT2NUM((long)(menu));
|
178
|
+
VALUE rb_menu = rb_hash_aref(menus_hash, menu_address);
|
179
|
+
|
180
|
+
if (rb_menu == Qnil)
|
181
|
+
{
|
182
|
+
rb_menu = Data_Wrap_Struct(cMENU, 0, 0, menu);
|
183
|
+
rb_iv_set(rb_menu, "@destroyed", Qfalse);
|
184
|
+
rb_hash_aset(menus_hash, menu_address, rb_menu);
|
185
|
+
}
|
186
|
+
return rb_menu;
|
187
|
+
}
|
188
|
+
}
|
189
|
+
static MENU *get_menu(VALUE rb_menu)
|
190
|
+
{
|
191
|
+
MENU *menu;
|
192
|
+
|
193
|
+
if (rb_menu == Qnil) return 0;
|
194
|
+
if (rb_iv_get(rb_menu, "@destroyed") == Qtrue)
|
195
|
+
{
|
196
|
+
rb_raise(rb_eRuntimeError, "Attempt to access a destroyed menu");
|
197
|
+
return 0;
|
198
|
+
}
|
199
|
+
Data_Get_Struct(rb_menu, MENU, menu);
|
200
|
+
return menu;
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
/*
|
205
|
+
* Proc objects are registered using hashes (one for each type of hook)
|
206
|
+
* The key in the hash is the address of the ncurses "object" and the value is
|
207
|
+
* the Proc object.
|
208
|
+
*/
|
209
|
+
#define ITEM_INIT_HOOK 0
|
210
|
+
#define ITEM_TERM_HOOK 1
|
211
|
+
#define MENU_INIT_HOOK 2
|
212
|
+
#define MENU_TERM_HOOK 3
|
213
|
+
#define PROC_HASHES_COUNT 4
|
214
|
+
static VALUE get_proc_hash(int hook)
|
215
|
+
{
|
216
|
+
VALUE arr = rb_iv_get(mMenu, "@proc_hashes");
|
217
|
+
VALUE hash = rb_ary_entry(arr, (long)hook);
|
218
|
+
|
219
|
+
if (hash == Qnil)
|
220
|
+
rb_raise(rb_eRuntimeError, "Invalid proc hash.");
|
221
|
+
return hash;
|
222
|
+
}
|
223
|
+
|
224
|
+
/*
|
225
|
+
* Returns an existing Ruby Proc for a given owning "object" and hook type.
|
226
|
+
* Qnil will be returned if no Proc was associated with the owner
|
227
|
+
*/
|
228
|
+
static VALUE get_proc(void *owner, int hook)
|
229
|
+
{
|
230
|
+
if (owner == 0) return Qnil;
|
231
|
+
{
|
232
|
+
VALUE owner_address = INT2NUM((long)(owner));
|
233
|
+
VALUE proc_hash = get_proc_hash(hook);
|
234
|
+
VALUE proc = rb_hash_aref(proc_hash, owner_address);
|
235
|
+
|
236
|
+
return proc;
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
/*
|
241
|
+
* Registers the Proc object with a given owner "object" and hook type.
|
242
|
+
* If proc is Qnil, the hook is unregistered instead.
|
243
|
+
*/
|
244
|
+
static void reg_proc(void *owner, int hook, VALUE proc)
|
245
|
+
{
|
246
|
+
if (owner == NULL) return;
|
247
|
+
{
|
248
|
+
VALUE proc_hash = get_proc_hash(hook);
|
249
|
+
VALUE owner_address = INT2NUM((long)(owner));
|
250
|
+
|
251
|
+
if (proc == Qnil)
|
252
|
+
rb_hash_delete(proc_hash, owner_address);
|
253
|
+
else
|
254
|
+
rb_hash_aset(proc_hash, owner_address, proc);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
|
259
|
+
/*
|
260
|
+
* Menu creation/destruction functions - menu_new(3X) man page
|
261
|
+
*/
|
262
|
+
static VALUE rbncurs_m_new_menu(VALUE dummy, VALUE rb_item_array)
|
263
|
+
{
|
264
|
+
long n = RARRAY_LEN(rb_item_array);
|
265
|
+
/* Will ncurses free this array? If not, must do it after calling free_menu(). */
|
266
|
+
ITEM **items = ALLOC_N(ITEM*, (n+1));
|
267
|
+
long i;
|
268
|
+
|
269
|
+
for (i=0; i<n; i++)
|
270
|
+
items[i] = get_item(rb_ary_entry(rb_item_array, i));
|
271
|
+
items[n] = NULL;
|
272
|
+
return wrap_menu(new_menu(items));
|
273
|
+
}
|
274
|
+
|
275
|
+
static VALUE rbncurs_c_free_menu(VALUE rb_menu)
|
276
|
+
{
|
277
|
+
VALUE menus_hash = rb_iv_get(mMenu, "@menus_hash");
|
278
|
+
MENU *menu = get_menu(rb_menu);
|
279
|
+
VALUE menu_address = INT2NUM((long)(menu));
|
280
|
+
|
281
|
+
rb_funcall(menus_hash, rb_intern("delete"), 1, menu_address);
|
282
|
+
rb_iv_set(rb_menu, "@destroyed", Qtrue);
|
283
|
+
return INT2NUM(free_menu(menu));
|
284
|
+
}
|
285
|
+
static VALUE rbncurs_m_free_menu(VALUE dummy, VALUE rb_menu)
|
286
|
+
{ return rbncurs_c_free_menu(rb_menu); }
|
287
|
+
|
288
|
+
|
289
|
+
/*
|
290
|
+
* Menu post/unpost functions - menu_post(3X) man page
|
291
|
+
*/
|
292
|
+
static VALUE rbncurs_c_post_menu(VALUE rb_menu)
|
293
|
+
{
|
294
|
+
MENU *menu = get_menu(rb_menu);
|
295
|
+
return INT2NUM(post_menu(menu));
|
296
|
+
}
|
297
|
+
static VALUE rbncurs_m_post_menu(VALUE dummy, VALUE rb_menu)
|
298
|
+
{ return rbncurs_c_post_menu(rb_menu); }
|
299
|
+
|
300
|
+
static VALUE rbncurs_c_unpost_menu(VALUE rb_menu)
|
301
|
+
{
|
302
|
+
MENU *menu = get_menu(rb_menu);
|
303
|
+
return INT2NUM(unpost_menu(menu));
|
304
|
+
}
|
305
|
+
static VALUE rbncurs_m_unpost_menu(VALUE dummy, VALUE rb_menu)
|
306
|
+
{ return rbncurs_c_unpost_menu(rb_menu); }
|
307
|
+
|
308
|
+
|
309
|
+
/*
|
310
|
+
* Menu driver - menu_driver(3X) man page
|
311
|
+
*/
|
312
|
+
static VALUE rbncurs_c_menu_driver(VALUE rb_menu, VALUE c)
|
313
|
+
{
|
314
|
+
MENU *menu = get_menu(rb_menu);
|
315
|
+
return INT2NUM(menu_driver(menu, NUM2INT(c)));
|
316
|
+
}
|
317
|
+
static VALUE rbncurs_m_menu_driver(VALUE dummy, VALUE rb_menu, VALUE c)
|
318
|
+
{ return rbncurs_c_menu_driver(rb_menu, c); }
|
319
|
+
|
320
|
+
|
321
|
+
/*
|
322
|
+
* Current menu item get/set functions - mitem_current(3X) man page
|
323
|
+
*/
|
324
|
+
static VALUE rbncurs_c_current_item(VALUE rb_menu)
|
325
|
+
{
|
326
|
+
MENU *menu = get_menu(rb_menu);
|
327
|
+
return wrap_item(current_item(menu));
|
328
|
+
}
|
329
|
+
static VALUE rbncurs_m_current_item(VALUE dummy, VALUE rb_menu)
|
330
|
+
{ return rbncurs_c_current_item(rb_menu); }
|
331
|
+
|
332
|
+
static VALUE rbncurs_c_set_current_item(VALUE rb_menu, VALUE rb_item)
|
333
|
+
{
|
334
|
+
MENU *menu = get_menu(rb_menu);
|
335
|
+
ITEM *item = get_item(rb_item);
|
336
|
+
return INT2NUM(set_current_item(menu, item));
|
337
|
+
}
|
338
|
+
static VALUE rbncurs_m_set_current_item(VALUE dummy, VALUE rb_menu, VALUE rb_item)
|
339
|
+
{ return rbncurs_c_set_current_item(rb_menu, rb_item); }
|
340
|
+
|
341
|
+
static VALUE rbncurs_c_top_row(VALUE rb_menu)
|
342
|
+
{
|
343
|
+
MENU *menu = get_menu(rb_menu);
|
344
|
+
return INT2NUM(top_row(menu));
|
345
|
+
}
|
346
|
+
static VALUE rbncurs_m_top_row(VALUE dummy, VALUE rb_menu)
|
347
|
+
{ return rbncurs_c_top_row(rb_menu); }
|
348
|
+
|
349
|
+
static VALUE rbncurs_c_set_top_row(VALUE rb_menu, VALUE n)
|
350
|
+
{
|
351
|
+
MENU *menu = get_menu(rb_menu);
|
352
|
+
return INT2NUM(set_top_row(menu, NUM2INT(n)));
|
353
|
+
}
|
354
|
+
static VALUE rbncurs_m_set_top_row(VALUE dummy, VALUE rb_menu, VALUE rb_item)
|
355
|
+
{ return rbncurs_c_set_top_row(rb_menu, rb_item); }
|
356
|
+
|
357
|
+
static VALUE rbncurs_c_item_index(VALUE rb_item)
|
358
|
+
{
|
359
|
+
ITEM *item = get_item(rb_item);
|
360
|
+
return INT2NUM(item_index(item));
|
361
|
+
}
|
362
|
+
static VALUE rbncurs_m_item_index(VALUE dummy, VALUE rb_item)
|
363
|
+
{ return rbncurs_c_item_index(rb_item); }
|
364
|
+
|
365
|
+
|
366
|
+
/*
|
367
|
+
* Item creation/destruction functions - mitem_new(3X) man page
|
368
|
+
*/
|
369
|
+
static VALUE rbncurs_m_new_item(VALUE dummy, VALUE name, VALUE description)
|
370
|
+
{ return wrap_item(new_item(StringValuePtr(name), StringValuePtr(description))); }
|
371
|
+
|
372
|
+
static VALUE rbncurs_c_free_item(VALUE rb_item)
|
373
|
+
{
|
374
|
+
VALUE items_hash = rb_iv_get(mMenu, "@items_hash");
|
375
|
+
ITEM *item = get_item(rb_item);
|
376
|
+
VALUE item_address = INT2NUM((long)(item));
|
377
|
+
rb_funcall(items_hash, rb_intern("delete"), 1, item_address);
|
378
|
+
rb_iv_set(rb_item, "@destroyed", Qtrue);
|
379
|
+
return INT2NUM(free_item(item));
|
380
|
+
}
|
381
|
+
static VALUE rbncurs_m_free_item(VALUE dummy, VALUE rb_item)
|
382
|
+
{ return rbncurs_c_free_item(rb_item); }
|
383
|
+
|
384
|
+
|
385
|
+
/*
|
386
|
+
* Item-menu connection make/break functions - menu_items(3X) man page
|
387
|
+
*/
|
388
|
+
static VALUE rbncurs_c_set_menu_items(VALUE rb_menu, VALUE rb_item_array)
|
389
|
+
{
|
390
|
+
long n = RARRAY_LEN(rb_item_array);
|
391
|
+
/* If ncurses does not free memory used by the previous array of strings, */
|
392
|
+
/* we will have to do it now. */
|
393
|
+
ITEM **items = ALLOC_N(ITEM*, (n+1));
|
394
|
+
long i;
|
395
|
+
MENU *menu = NULL;
|
396
|
+
|
397
|
+
for (i=0; i<n; i++)
|
398
|
+
items[i] = get_item(rb_ary_entry(rb_item_array, i));
|
399
|
+
items[n] = NULL;
|
400
|
+
menu = get_menu(rb_menu);
|
401
|
+
return INT2NUM(set_menu_items(menu, items));
|
402
|
+
}
|
403
|
+
static VALUE rbncurs_m_set_menu_items(VALUE dummy, VALUE rb_menu, VALUE rb_item_array)
|
404
|
+
{ return rbncurs_c_set_menu_items(rb_menu, rb_item_array); }
|
405
|
+
|
406
|
+
static VALUE rbncurs_c_menu_items(VALUE rb_menu)
|
407
|
+
{
|
408
|
+
MENU *menu = get_menu(rb_menu);
|
409
|
+
ITEM **items = menu_items(menu);
|
410
|
+
VALUE arr = Qundef;
|
411
|
+
int i;
|
412
|
+
|
413
|
+
if (items == NULL)
|
414
|
+
rb_raise(rb_eRuntimeError, "Error retrieving menu items");
|
415
|
+
arr = rb_ary_new();
|
416
|
+
i=0;
|
417
|
+
while (items[i] != NULL)
|
418
|
+
rb_ary_push(arr, wrap_item(items[i++]));
|
419
|
+
return arr;
|
420
|
+
}
|
421
|
+
static VALUE rbncurs_m_menu_items(VALUE dummy, VALUE rb_menu)
|
422
|
+
{ return rbncurs_c_menu_items(rb_menu); }
|
423
|
+
|
424
|
+
static VALUE rbncurs_c_item_count(VALUE rb_menu)
|
425
|
+
{
|
426
|
+
MENU *menu = get_menu(rb_menu);
|
427
|
+
return INT2NUM(item_count(menu));
|
428
|
+
}
|
429
|
+
static VALUE rbncurs_m_item_count(VALUE dummy, VALUE rb_menu)
|
430
|
+
{ return rbncurs_c_item_count(rb_menu); }
|
431
|
+
|
432
|
+
|
433
|
+
/*
|
434
|
+
* Item/menu hook get/set functions - menu_hook(3X) man page
|
435
|
+
*/
|
436
|
+
static void item_init_hook(MENU *menu)
|
437
|
+
{
|
438
|
+
/* Find the Proc object associated with this menu */
|
439
|
+
VALUE proc = get_proc(menu, ITEM_INIT_HOOK);
|
440
|
+
|
441
|
+
if (proc != Qnil)
|
442
|
+
{
|
443
|
+
VALUE rb_menu = wrap_menu(menu);
|
444
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_menu);
|
445
|
+
}
|
446
|
+
}
|
447
|
+
static VALUE rbncurs_c_set_item_init(VALUE rb_menu, VALUE proc)
|
448
|
+
{
|
449
|
+
MENU *menu = NULL;
|
450
|
+
|
451
|
+
if (!rb_obj_is_kind_of(rb_menu, cMENU))
|
452
|
+
rb_raise(rb_eArgError, "arg1 must be a MENU object");
|
453
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
454
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
455
|
+
menu = get_menu(rb_menu);
|
456
|
+
reg_proc(menu, ITEM_INIT_HOOK, proc);
|
457
|
+
if (proc != Qnil)
|
458
|
+
return INT2NUM(set_item_init(menu, item_init_hook));
|
459
|
+
else
|
460
|
+
return INT2NUM(set_item_init(menu, NULL));
|
461
|
+
}
|
462
|
+
static VALUE rbncurs_m_set_item_init(VALUE dummy, VALUE rb_menu, VALUE proc)
|
463
|
+
{ return rbncurs_c_set_item_init(rb_menu, proc); }
|
464
|
+
|
465
|
+
static VALUE rbncurs_c_item_init(VALUE rb_menu)
|
466
|
+
{
|
467
|
+
MENU *menu = get_menu(rb_menu);
|
468
|
+
return get_proc(menu, ITEM_INIT_HOOK);
|
469
|
+
}
|
470
|
+
static VALUE rbncurs_m_item_init(VALUE dummy, VALUE rb_menu)
|
471
|
+
{ return rbncurs_c_item_init(rb_menu); }
|
472
|
+
|
473
|
+
static void item_term_hook(MENU *menu)
|
474
|
+
{
|
475
|
+
/* Find the Proc object associated with this menu */
|
476
|
+
VALUE proc = get_proc(menu, ITEM_TERM_HOOK);
|
477
|
+
|
478
|
+
if (proc != Qnil)
|
479
|
+
{
|
480
|
+
VALUE rb_menu = wrap_menu(menu);
|
481
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_menu);
|
482
|
+
}
|
483
|
+
}
|
484
|
+
static VALUE rbncurs_c_set_item_term(VALUE rb_menu, VALUE proc)
|
485
|
+
{
|
486
|
+
MENU *menu = NULL;
|
487
|
+
|
488
|
+
if (!rb_obj_is_kind_of(rb_menu, cMENU))
|
489
|
+
rb_raise(rb_eArgError, "arg1 must be a MENU object");
|
490
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
491
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
492
|
+
menu = get_menu(rb_menu);
|
493
|
+
reg_proc(menu, ITEM_TERM_HOOK, proc);
|
494
|
+
if (proc != Qnil)
|
495
|
+
return INT2NUM(set_item_term(menu, item_term_hook));
|
496
|
+
else
|
497
|
+
return INT2NUM(set_item_term(menu, NULL));
|
498
|
+
}
|
499
|
+
static VALUE rbncurs_m_set_item_term(VALUE dummy, VALUE rb_menu, VALUE proc)
|
500
|
+
{ return rbncurs_c_set_item_term(rb_menu, proc); }
|
501
|
+
|
502
|
+
static VALUE rbncurs_c_item_term(VALUE rb_menu)
|
503
|
+
{
|
504
|
+
MENU *menu = get_menu(rb_menu);
|
505
|
+
return get_proc(menu, ITEM_TERM_HOOK);
|
506
|
+
}
|
507
|
+
static VALUE rbncurs_m_item_term(VALUE dummy, VALUE rb_menu)
|
508
|
+
{ return rbncurs_c_item_term(rb_menu); }
|
509
|
+
|
510
|
+
static void menu_init_hook(MENU *menu)
|
511
|
+
{
|
512
|
+
/* Find the Proc object associated with this menu */
|
513
|
+
VALUE proc = get_proc(menu, MENU_INIT_HOOK);
|
514
|
+
|
515
|
+
if (proc != Qnil)
|
516
|
+
{
|
517
|
+
VALUE rb_menu = wrap_menu(menu);
|
518
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_menu);
|
519
|
+
}
|
520
|
+
}
|
521
|
+
static VALUE rbncurs_c_set_menu_init(VALUE rb_menu, VALUE proc) {
|
522
|
+
MENU *menu = NULL;
|
523
|
+
|
524
|
+
if (!rb_obj_is_kind_of(rb_menu, cMENU))
|
525
|
+
rb_raise(rb_eArgError, "arg1 must be a MENU object");
|
526
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
527
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
528
|
+
menu = get_menu(rb_menu);
|
529
|
+
reg_proc(menu, MENU_INIT_HOOK, proc);
|
530
|
+
if (proc != Qnil)
|
531
|
+
return INT2NUM(set_menu_init(menu, menu_init_hook));
|
532
|
+
else
|
533
|
+
return INT2NUM(set_menu_init(menu, NULL));
|
534
|
+
}
|
535
|
+
static VALUE rbncurs_m_set_menu_init(VALUE dummy, VALUE rb_menu, VALUE proc)
|
536
|
+
{ return rbncurs_c_set_menu_init(rb_menu, proc); }
|
537
|
+
|
538
|
+
static VALUE rbncurs_c_menu_init(VALUE rb_menu)
|
539
|
+
{
|
540
|
+
MENU *menu = get_menu(rb_menu);
|
541
|
+
return get_proc(menu, MENU_INIT_HOOK);
|
542
|
+
}
|
543
|
+
static VALUE rbncurs_m_menu_init(VALUE dummy, VALUE rb_menu)
|
544
|
+
{ return rbncurs_c_menu_init(rb_menu); }
|
545
|
+
|
546
|
+
static void menu_term_hook(MENU *menu)
|
547
|
+
{
|
548
|
+
/* Find the Proc object associated with this menu */
|
549
|
+
VALUE proc = get_proc(menu, MENU_TERM_HOOK);
|
550
|
+
|
551
|
+
if (proc != Qnil)
|
552
|
+
{
|
553
|
+
VALUE rb_menu = wrap_menu(menu);
|
554
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_menu);
|
555
|
+
}
|
556
|
+
}
|
557
|
+
static VALUE rbncurs_c_set_menu_term(VALUE rb_menu, VALUE proc)
|
558
|
+
{
|
559
|
+
MENU *menu = NULL;
|
560
|
+
|
561
|
+
if (!rb_obj_is_kind_of(rb_menu, cMENU))
|
562
|
+
rb_raise(rb_eArgError, "arg1 must be a MENU object");
|
563
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
564
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
565
|
+
menu = get_menu(rb_menu);
|
566
|
+
reg_proc(menu, MENU_TERM_HOOK, proc);
|
567
|
+
if (proc != Qnil)
|
568
|
+
return INT2NUM(set_menu_term(menu, menu_term_hook));
|
569
|
+
else
|
570
|
+
return INT2NUM(set_menu_term(menu, NULL));
|
571
|
+
}
|
572
|
+
static VALUE rbncurs_m_set_menu_term(VALUE dummy, VALUE rb_menu, VALUE proc)
|
573
|
+
{ return rbncurs_c_set_menu_term(rb_menu, proc); }
|
574
|
+
|
575
|
+
static VALUE rbncurs_c_menu_term(VALUE rb_menu)
|
576
|
+
{
|
577
|
+
MENU *menu = get_menu(rb_menu);
|
578
|
+
return get_proc(menu, MENU_TERM_HOOK);
|
579
|
+
}
|
580
|
+
static VALUE rbncurs_m_menu_term(VALUE dummy, VALUE rb_menu)
|
581
|
+
{ return rbncurs_c_menu_term(rb_menu); }
|
582
|
+
|
583
|
+
|
584
|
+
/*
|
585
|
+
* Item option get/set functions - mitem_opts(3X) man page
|
586
|
+
*/
|
587
|
+
static VALUE rbncurs_c_set_item_opts(VALUE rb_item, VALUE opts)
|
588
|
+
{
|
589
|
+
ITEM *item = get_item(rb_item);
|
590
|
+
return INT2NUM(set_item_opts(item, NUM2INT(opts)));
|
591
|
+
}
|
592
|
+
static VALUE rbncurs_m_set_item_opts(VALUE dummy, VALUE rb_item, VALUE opts)
|
593
|
+
{ return rbncurs_c_set_item_opts(rb_item, opts); }
|
594
|
+
|
595
|
+
static VALUE rbncurs_c_item_opts_on(VALUE rb_item, VALUE opts)
|
596
|
+
{
|
597
|
+
ITEM *item = get_item(rb_item);
|
598
|
+
return INT2NUM(item_opts_on(item, NUM2INT(opts)));
|
599
|
+
}
|
600
|
+
static VALUE rbncurs_m_item_opts_on(VALUE dummy, VALUE rb_item, VALUE opts)
|
601
|
+
{ return rbncurs_c_item_opts_on(rb_item, opts); }
|
602
|
+
|
603
|
+
static VALUE rbncurs_c_item_opts_off(VALUE rb_item, VALUE opts)
|
604
|
+
{
|
605
|
+
ITEM *item = get_item(rb_item);
|
606
|
+
return INT2NUM(item_opts_off(item, NUM2INT(opts)));
|
607
|
+
}
|
608
|
+
static VALUE rbncurs_m_item_opts_off(VALUE dummy, VALUE rb_item, VALUE opts)
|
609
|
+
{ return rbncurs_c_item_opts_off(rb_item, opts); }
|
610
|
+
|
611
|
+
static VALUE rbncurs_c_item_opts(VALUE rb_item)
|
612
|
+
{
|
613
|
+
ITEM *item = get_item(rb_item);
|
614
|
+
return INT2NUM(item_opts(item));
|
615
|
+
}
|
616
|
+
static VALUE rbncurs_m_item_opts(VALUE dummy, VALUE rb_item)
|
617
|
+
{ return rbncurs_c_item_opts(rb_item); }
|
618
|
+
|
619
|
+
|
620
|
+
/*
|
621
|
+
* Menu option get/set functions - menu_opts(3X) man page
|
622
|
+
*/
|
623
|
+
static VALUE rbncurs_c_set_menu_opts(VALUE rb_menu, VALUE opts)
|
624
|
+
{
|
625
|
+
MENU *menu = get_menu(rb_menu);
|
626
|
+
return INT2NUM(set_menu_opts(menu, NUM2INT(opts)));
|
627
|
+
}
|
628
|
+
static VALUE rbncurs_m_set_menu_opts(VALUE dummy, VALUE rb_menu, VALUE opts)
|
629
|
+
{ return rbncurs_c_set_menu_opts(rb_menu, opts); }
|
630
|
+
|
631
|
+
static VALUE rbncurs_c_menu_opts_on(VALUE rb_menu, VALUE opts)
|
632
|
+
{
|
633
|
+
MENU *menu = get_menu(rb_menu);
|
634
|
+
return INT2NUM(menu_opts_on(menu, NUM2INT(opts)));
|
635
|
+
}
|
636
|
+
static VALUE rbncurs_m_menu_opts_on(VALUE dummy, VALUE rb_menu, VALUE opts)
|
637
|
+
{ return rbncurs_c_menu_opts_on(rb_menu, opts); }
|
638
|
+
|
639
|
+
static VALUE rbncurs_c_menu_opts_off(VALUE rb_menu, VALUE opts)
|
640
|
+
{
|
641
|
+
MENU *menu = get_menu(rb_menu);
|
642
|
+
return INT2NUM(menu_opts_off(menu, NUM2INT(opts)));
|
643
|
+
}
|
644
|
+
static VALUE rbncurs_m_menu_opts_off(VALUE dummy, VALUE rb_menu, VALUE opts)
|
645
|
+
{ return rbncurs_c_menu_opts_off(rb_menu, opts); }
|
646
|
+
|
647
|
+
static VALUE rbncurs_c_menu_opts(VALUE rb_menu)
|
648
|
+
{
|
649
|
+
MENU *menu = get_menu(rb_menu);
|
650
|
+
return INT2NUM(menu_opts(menu));
|
651
|
+
}
|
652
|
+
static VALUE rbncurs_m_menu_opts(VALUE dummy, VALUE rb_menu)
|
653
|
+
{ return rbncurs_c_menu_opts(rb_menu); }
|
654
|
+
|
655
|
+
|
656
|
+
/*
|
657
|
+
* Printable menu request name handling functions - menu_requestname(3X) man page
|
658
|
+
*/
|
659
|
+
static VALUE rbncurs_c_menu_request_name(VALUE request)
|
660
|
+
{
|
661
|
+
return rb_str_new2(menu_request_name(NUM2INT(request)));
|
662
|
+
}
|
663
|
+
static VALUE rbncurs_m_menu_request_name(VALUE dummy, VALUE request)
|
664
|
+
{ return rbncurs_c_menu_request_name(request); }
|
665
|
+
|
666
|
+
static VALUE rbncurs_c_menu_request_by_name(VALUE name)
|
667
|
+
{
|
668
|
+
return INT2NUM(menu_request_by_name(StringValuePtr(name)));
|
669
|
+
}
|
670
|
+
static VALUE rbncurs_m_menu_request_by_name(VALUE dummy, VALUE name)
|
671
|
+
{ return rbncurs_c_menu_request_by_name(name); }
|
672
|
+
|
673
|
+
|
674
|
+
/*
|
675
|
+
* (Sub)window association make/break functions - menu_win(3X) man page
|
676
|
+
*/
|
677
|
+
static VALUE rbncurs_c_set_menu_win(VALUE rb_menu, VALUE rb_win)
|
678
|
+
{
|
679
|
+
MENU *menu = get_menu(rb_menu);
|
680
|
+
WINDOW *win = get_window(rb_win);
|
681
|
+
return INT2NUM(set_menu_win(menu, win));
|
682
|
+
}
|
683
|
+
static VALUE rbncurs_m_set_menu_win(VALUE dummy, VALUE rb_menu, VALUE rb_win)
|
684
|
+
{ return rbncurs_c_set_menu_win(rb_menu, rb_win); }
|
685
|
+
|
686
|
+
static VALUE rbncurs_c_menu_win(VALUE rb_menu)
|
687
|
+
{
|
688
|
+
MENU *menu = get_menu(rb_menu);
|
689
|
+
return wrap_window(menu_win(menu));
|
690
|
+
}
|
691
|
+
static VALUE rbncurs_m_menu_win(VALUE dummy, VALUE rb_menu)
|
692
|
+
{ return rbncurs_c_menu_win(rb_menu); }
|
693
|
+
|
694
|
+
static VALUE rbncurs_c_set_menu_sub(VALUE rb_menu, VALUE rb_sub)
|
695
|
+
{
|
696
|
+
MENU *menu = get_menu(rb_menu);
|
697
|
+
WINDOW *win = get_window(rb_sub);
|
698
|
+
return INT2NUM(set_menu_sub(menu, win));
|
699
|
+
}
|
700
|
+
static VALUE rbncurs_m_set_menu_sub(VALUE dummy, VALUE rb_menu, VALUE rb_sub)
|
701
|
+
{ return rbncurs_c_set_menu_sub(rb_menu, rb_sub); }
|
702
|
+
|
703
|
+
static VALUE rbncurs_c_menu_sub(VALUE rb_menu)
|
704
|
+
{
|
705
|
+
MENU *menu = get_menu(rb_menu);
|
706
|
+
return wrap_window(menu_sub(menu));
|
707
|
+
}
|
708
|
+
static VALUE rbncurs_m_menu_sub(VALUE dummy, VALUE rb_menu)
|
709
|
+
{ return rbncurs_c_menu_sub(rb_menu); }
|
710
|
+
|
711
|
+
static VALUE rbncurs_c_scale_menu(VALUE rb_menu, VALUE rows, VALUE columns)
|
712
|
+
{
|
713
|
+
MENU *menu = get_menu(rb_menu);
|
714
|
+
|
715
|
+
if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue ||
|
716
|
+
rb_obj_is_instance_of(columns, rb_cArray) != Qtrue)
|
717
|
+
{
|
718
|
+
rb_raise(rb_eArgError, "rows and columns arguments must be empty Arrays");
|
719
|
+
return Qnil;
|
720
|
+
}
|
721
|
+
else
|
722
|
+
{
|
723
|
+
int vals[2] = {0,0};
|
724
|
+
int result = scale_menu(menu, &vals[0],&vals[1]);
|
725
|
+
|
726
|
+
rb_ary_push(rows, INT2NUM(vals[0]));
|
727
|
+
rb_ary_push(columns, INT2NUM(vals[1]));
|
728
|
+
return INT2NUM(result);
|
729
|
+
}
|
730
|
+
}
|
731
|
+
static VALUE rbncurs_m_scale_menu(VALUE dummy, VALUE rb_menu, VALUE rows, VALUE columns)
|
732
|
+
{ return rbncurs_c_scale_menu(rb_menu, rows, columns); }
|
733
|
+
|
734
|
+
|
735
|
+
/*
|
736
|
+
* Menu cursor positioning functions - menu_cursor(3X) man page
|
737
|
+
*/
|
738
|
+
static VALUE rbncurs_c_pos_menu_cursor(VALUE rb_menu)
|
739
|
+
{
|
740
|
+
MENU *menu = get_menu(rb_menu);
|
741
|
+
return INT2NUM(pos_menu_cursor(menu));
|
742
|
+
}
|
743
|
+
static VALUE rbncurs_m_pos_menu_cursor(VALUE dummy, VALUE rb_menu)
|
744
|
+
{ return rbncurs_c_pos_menu_cursor(rb_menu); }
|
745
|
+
|
746
|
+
|
747
|
+
/*
|
748
|
+
* Item name/description retrieval functions - mitem_name(3X) man page
|
749
|
+
*/
|
750
|
+
static VALUE rbncurs_c_item_name(VALUE rb_item)
|
751
|
+
{
|
752
|
+
ITEM *item = get_item(rb_item);
|
753
|
+
return rb_str_new2(item_name(item));
|
754
|
+
}
|
755
|
+
static VALUE rbncurs_m_item_name(VALUE dummy, VALUE rb_item)
|
756
|
+
{ return rbncurs_c_item_name(rb_item); }
|
757
|
+
|
758
|
+
static VALUE rbncurs_c_item_description(VALUE rb_item)
|
759
|
+
{
|
760
|
+
ITEM *item = get_item(rb_item);
|
761
|
+
return rb_str_new2(item_description(item));
|
762
|
+
}
|
763
|
+
static VALUE rbncurs_m_item_description(VALUE dummy, VALUE rb_item)
|
764
|
+
{ return rbncurs_c_item_description(rb_item); }
|
765
|
+
|
766
|
+
|
767
|
+
/*
|
768
|
+
* Item value get/set functions - mitem_value(3X) man page
|
769
|
+
*/
|
770
|
+
static VALUE rbncurs_c_set_item_value(VALUE rb_item, VALUE value)
|
771
|
+
{
|
772
|
+
ITEM *item = get_item(rb_item);
|
773
|
+
return INT2NUM(set_item_value(item, RTEST(value)));
|
774
|
+
}
|
775
|
+
static VALUE rbncurs_m_set_item_value(VALUE dummy, VALUE rb_item, VALUE value)
|
776
|
+
{ return rbncurs_c_set_item_value(rb_item, value); }
|
777
|
+
|
778
|
+
static VALUE rbncurs_c_item_value(VALUE rb_item)
|
779
|
+
{
|
780
|
+
ITEM *item = get_item(rb_item);
|
781
|
+
return (item_value(item)) ? Qtrue: Qfalse;
|
782
|
+
}
|
783
|
+
static VALUE rbncurs_m_item_value(VALUE dummy, VALUE rb_item)
|
784
|
+
{ return rbncurs_c_item_value(rb_item); }
|
785
|
+
|
786
|
+
|
787
|
+
/*
|
788
|
+
* Item visibility retrieval function - mitem_visible(3X) man page
|
789
|
+
*/
|
790
|
+
static VALUE rbncurs_c_item_visible(VALUE rb_item)
|
791
|
+
{
|
792
|
+
ITEM *item = get_item(rb_item);
|
793
|
+
return (item_visible(item)) ? Qtrue: Qfalse;
|
794
|
+
}
|
795
|
+
static VALUE rbncurs_m_item_visible(VALUE dummy, VALUE rb_item)
|
796
|
+
{ return rbncurs_c_item_visible(rb_item); }
|
797
|
+
|
798
|
+
|
799
|
+
/*
|
800
|
+
* Menu attribute get/set functions - menu_attributes(3X) man page
|
801
|
+
*/
|
802
|
+
static VALUE rbncurs_c_set_menu_fore(VALUE rb_menu, VALUE attr)
|
803
|
+
{
|
804
|
+
MENU *menu = get_menu(rb_menu);
|
805
|
+
return INT2NUM(set_menu_fore(menu, NUM2ULONG(attr)));
|
806
|
+
}
|
807
|
+
static VALUE rbncurs_m_set_menu_fore(VALUE dummy, VALUE rb_menu, VALUE attr)
|
808
|
+
{ return rbncurs_c_set_menu_fore(rb_menu, attr); }
|
809
|
+
|
810
|
+
static VALUE rbncurs_c_menu_fore(VALUE rb_menu)
|
811
|
+
{
|
812
|
+
MENU *menu = get_menu(rb_menu);
|
813
|
+
return ULONG2NUM(menu_fore(menu));
|
814
|
+
}
|
815
|
+
static VALUE rbncurs_m_menu_fore(VALUE dummy, VALUE rb_menu)
|
816
|
+
{ return rbncurs_c_menu_fore(rb_menu); }
|
817
|
+
|
818
|
+
static VALUE rbncurs_c_set_menu_back(VALUE rb_menu, VALUE attr)
|
819
|
+
{
|
820
|
+
MENU *menu = get_menu(rb_menu);
|
821
|
+
return INT2NUM(set_menu_back(menu, NUM2ULONG(attr)));
|
822
|
+
}
|
823
|
+
static VALUE rbncurs_m_set_menu_back(VALUE dummy, VALUE rb_menu, VALUE attr)
|
824
|
+
{ return rbncurs_c_set_menu_back(rb_menu, attr); }
|
825
|
+
|
826
|
+
static VALUE rbncurs_c_menu_back(VALUE rb_menu)
|
827
|
+
{
|
828
|
+
MENU *menu = get_menu(rb_menu);
|
829
|
+
return ULONG2NUM(menu_back(menu));
|
830
|
+
}
|
831
|
+
static VALUE rbncurs_m_menu_back(VALUE dummy, VALUE rb_menu)
|
832
|
+
{ return rbncurs_c_menu_back(rb_menu); }
|
833
|
+
|
834
|
+
static VALUE rbncurs_c_set_menu_grey(VALUE rb_menu, VALUE attr)
|
835
|
+
{
|
836
|
+
MENU *menu = get_menu(rb_menu);
|
837
|
+
return INT2NUM(set_menu_grey(menu, NUM2ULONG(attr)));
|
838
|
+
}
|
839
|
+
static VALUE rbncurs_m_set_menu_grey(VALUE dummy, VALUE rb_menu, VALUE attr)
|
840
|
+
{ return rbncurs_c_set_menu_grey(rb_menu, attr); }
|
841
|
+
|
842
|
+
static VALUE rbncurs_c_menu_grey(VALUE rb_menu)
|
843
|
+
{
|
844
|
+
MENU *menu = get_menu(rb_menu);
|
845
|
+
return ULONG2NUM(menu_grey(menu));
|
846
|
+
}
|
847
|
+
static VALUE rbncurs_m_menu_grey(VALUE dummy, VALUE rb_menu)
|
848
|
+
{ return rbncurs_c_menu_grey(rb_menu); }
|
849
|
+
|
850
|
+
static VALUE rbncurs_c_set_menu_pad(VALUE rb_menu, VALUE pad)
|
851
|
+
{
|
852
|
+
MENU *menu = get_menu(rb_menu);
|
853
|
+
return INT2NUM(set_menu_pad(menu, NUM2INT(pad)));
|
854
|
+
}
|
855
|
+
static VALUE rbncurs_m_set_menu_pad(VALUE dummy, VALUE rb_menu, VALUE pad)
|
856
|
+
{ return rbncurs_c_set_menu_pad(rb_menu, pad); }
|
857
|
+
|
858
|
+
static VALUE rbncurs_c_menu_pad(VALUE rb_menu)
|
859
|
+
{
|
860
|
+
MENU *menu = get_menu(rb_menu);
|
861
|
+
return INT2NUM(menu_pad(menu));
|
862
|
+
}
|
863
|
+
static VALUE rbncurs_m_menu_pad(VALUE dummy, VALUE rb_menu)
|
864
|
+
{ return rbncurs_c_menu_pad(rb_menu); }
|
865
|
+
|
866
|
+
|
867
|
+
/*
|
868
|
+
* Menu format get/set functions - menu_format(3X) man page
|
869
|
+
*/
|
870
|
+
static VALUE rbncurs_c_set_menu_format(VALUE rb_menu, VALUE rows, VALUE cols)
|
871
|
+
{
|
872
|
+
MENU *menu = get_menu(rb_menu);
|
873
|
+
return INT2NUM(set_menu_format(menu, NUM2INT(rows), NUM2INT(cols)));
|
874
|
+
}
|
875
|
+
static VALUE rbncurs_m_set_menu_format(VALUE dummy, VALUE rb_menu, VALUE rows, VALUE cols)
|
876
|
+
{ return rbncurs_c_set_menu_format(rb_menu, rows, cols); }
|
877
|
+
|
878
|
+
static VALUE rbncurs_c_menu_format(VALUE rb_menu, VALUE rows, VALUE cols)
|
879
|
+
{
|
880
|
+
if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue ||
|
881
|
+
rb_obj_is_instance_of(cols, rb_cArray) != Qtrue)
|
882
|
+
{
|
883
|
+
rb_raise(rb_eArgError, "rows and cols arguments must be empty Arrays");
|
884
|
+
return Qnil;
|
885
|
+
}
|
886
|
+
else
|
887
|
+
{
|
888
|
+
MENU *menu = get_menu(rb_menu);
|
889
|
+
int vals[2] = {0,0};
|
890
|
+
|
891
|
+
menu_format(menu, &vals[0], &vals[1]);
|
892
|
+
rb_ary_push(rows, INT2NUM(vals[0]));
|
893
|
+
rb_ary_push(cols, INT2NUM(vals[1]));
|
894
|
+
return Qnil;
|
895
|
+
}
|
896
|
+
}
|
897
|
+
static VALUE rbncurs_m_menu_format(VALUE dummy, VALUE rb_menu, VALUE rows, VALUE cols)
|
898
|
+
{ return rbncurs_c_menu_format(rb_menu, rows, cols); }
|
899
|
+
|
900
|
+
|
901
|
+
/*
|
902
|
+
* Menu mark get/set functions - menu_mark(3X) man page
|
903
|
+
*/
|
904
|
+
static VALUE rbncurs_c_set_menu_mark(VALUE rb_menu, VALUE value)
|
905
|
+
{
|
906
|
+
MENU *menu = get_menu(rb_menu);
|
907
|
+
return INT2NUM(set_menu_mark(menu, StringValuePtr(value)));
|
908
|
+
}
|
909
|
+
static VALUE rbncurs_m_set_menu_mark(VALUE dummy, VALUE rb_field, VALUE value)
|
910
|
+
{ return rbncurs_c_set_menu_mark(rb_field, value); }
|
911
|
+
|
912
|
+
static VALUE rbncurs_c_menu_mark(VALUE rb_menu)
|
913
|
+
{
|
914
|
+
MENU *menu = get_menu(rb_menu);
|
915
|
+
return rb_str_new2(menu_mark(menu));
|
916
|
+
}
|
917
|
+
static VALUE rbncurs_m_menu_mark(VALUE dummy, VALUE rb_menu)
|
918
|
+
{ return rbncurs_c_menu_mark(rb_menu); }
|
919
|
+
|
920
|
+
|
921
|
+
/*
|
922
|
+
* Menu pattern get/set functions - menu_pattern(3X) man page
|
923
|
+
*/
|
924
|
+
static VALUE rbncurs_c_set_menu_pattern(VALUE rb_menu, VALUE pattern)
|
925
|
+
{
|
926
|
+
MENU *menu = get_menu(rb_menu);
|
927
|
+
return INT2NUM(set_menu_pattern(menu, StringValuePtr(pattern)));
|
928
|
+
}
|
929
|
+
static VALUE rbncurs_m_set_menu_pattern(VALUE dummy, VALUE rb_menu, VALUE pattern)
|
930
|
+
{ return rbncurs_c_set_menu_pattern(rb_menu, pattern); }
|
931
|
+
|
932
|
+
static VALUE rbncurs_c_menu_pattern(VALUE rb_menu)
|
933
|
+
{
|
934
|
+
MENU *menu = get_menu(rb_menu);
|
935
|
+
return rb_str_new2(menu_pattern(menu));
|
936
|
+
}
|
937
|
+
static VALUE rbncurs_m_menu_pattern(VALUE dummy, VALUE rb_menu)
|
938
|
+
{ return rbncurs_c_menu_pattern(rb_menu); }
|
939
|
+
|
940
|
+
|
941
|
+
/*
|
942
|
+
* Menu spacing get/set functions - menu_spacing(3X) man page
|
943
|
+
*/
|
944
|
+
static VALUE rbncurs_c_set_menu_spacing(VALUE rb_menu, VALUE spc_description,
|
945
|
+
VALUE spc_rows, VALUE spc_cols)
|
946
|
+
{
|
947
|
+
MENU *menu = get_menu(rb_menu);
|
948
|
+
return INT2NUM(set_menu_spacing(menu, NUM2INT(spc_description),
|
949
|
+
NUM2INT(spc_rows), NUM2INT(spc_cols)));
|
950
|
+
}
|
951
|
+
static VALUE rbncurs_m_set_menu_spacing(VALUE dummy, VALUE rb_menu, VALUE spc_description,
|
952
|
+
VALUE spc_rows, VALUE spc_cols)
|
953
|
+
{ return rbncurs_c_set_menu_spacing(rb_menu, spc_description, spc_rows, spc_cols); }
|
954
|
+
|
955
|
+
static VALUE rbncurs_c_menu_spacing(VALUE rb_menu, VALUE spc_description,
|
956
|
+
VALUE spc_rows, VALUE spc_cols)
|
957
|
+
{
|
958
|
+
if (rb_obj_is_instance_of(spc_description, rb_cArray) != Qtrue ||
|
959
|
+
rb_obj_is_instance_of(spc_rows, rb_cArray) != Qtrue ||
|
960
|
+
rb_obj_is_instance_of(spc_cols, rb_cArray) != Qtrue)
|
961
|
+
{
|
962
|
+
rb_raise(rb_eArgError, "spc_description, spc_rows, and spc_cols arguments must be empty Arrays");
|
963
|
+
return Qnil;
|
964
|
+
}
|
965
|
+
else
|
966
|
+
{
|
967
|
+
MENU *menu = get_menu(rb_menu);
|
968
|
+
int vals[3] = {0,0,0};
|
969
|
+
|
970
|
+
int result = menu_spacing(menu, &vals[0], &vals[1], &vals[2]);
|
971
|
+
rb_ary_push(spc_description, INT2NUM(vals[0]));
|
972
|
+
rb_ary_push(spc_rows, INT2NUM(vals[1]));
|
973
|
+
rb_ary_push(spc_cols, INT2NUM(vals[2]));
|
974
|
+
return INT2NUM(result);
|
975
|
+
}
|
976
|
+
}
|
977
|
+
static VALUE rbncurs_m_menu_spacing(VALUE dummy, VALUE rb_menu, VALUE spc_description,
|
978
|
+
VALUE spc_rows, VALUE spc_cols)
|
979
|
+
{ return rbncurs_c_menu_spacing(rb_menu, spc_description, spc_rows, spc_cols); }
|
980
|
+
|
981
|
+
|
982
|
+
/*
|
983
|
+
* Menu initialization function
|
984
|
+
*/
|
985
|
+
void init_menu(void)
|
986
|
+
{
|
987
|
+
mMenu = rb_define_module_under(mNcurses, "Menu");
|
988
|
+
|
989
|
+
MENU_SNG_FUNC(current_item, 1);
|
990
|
+
MENU_SNG_FUNC(free_item, 1);
|
991
|
+
MENU_SNG_FUNC(free_menu, 1);
|
992
|
+
MENU_SNG_FUNC(item_count, 1);
|
993
|
+
MENU_SNG_FUNC(item_description, 1);
|
994
|
+
MENU_SNG_FUNC(item_index, 1);
|
995
|
+
MENU_SNG_FUNC(item_init, 1);
|
996
|
+
MENU_SNG_FUNC(item_name, 1);
|
997
|
+
MENU_SNG_FUNC(item_opts, 1);
|
998
|
+
MENU_SNG_FUNC(item_opts_off, 2);
|
999
|
+
MENU_SNG_FUNC(item_opts_on, 2);
|
1000
|
+
MENU_SNG_FUNC(item_term, 1);
|
1001
|
+
/* MENU_SNG_FUNC(item_userptr, 1); */
|
1002
|
+
MENU_SNG_FUNC(item_value, 1);
|
1003
|
+
MENU_SNG_FUNC(item_visible, 1);
|
1004
|
+
MENU_SNG_FUNC(menu_back, 1);
|
1005
|
+
MENU_SNG_FUNC(menu_driver, 2);
|
1006
|
+
MENU_SNG_FUNC(menu_fore, 1);
|
1007
|
+
MENU_SNG_FUNC(menu_format, 3);
|
1008
|
+
MENU_SNG_FUNC(menu_grey, 1);
|
1009
|
+
MENU_SNG_FUNC(menu_init, 1);
|
1010
|
+
MENU_SNG_FUNC(menu_items, 1);
|
1011
|
+
MENU_SNG_FUNC(menu_mark, 1);
|
1012
|
+
MENU_SNG_FUNC(menu_opts, 1);
|
1013
|
+
MENU_SNG_FUNC(menu_opts_off, 2);
|
1014
|
+
MENU_SNG_FUNC(menu_opts_on, 2);
|
1015
|
+
MENU_SNG_FUNC(menu_pad, 1);
|
1016
|
+
MENU_SNG_FUNC(menu_pattern, 1);
|
1017
|
+
MENU_SNG_FUNC(menu_request_by_name, 1);
|
1018
|
+
MENU_SNG_FUNC(menu_request_name, 1);
|
1019
|
+
MENU_SNG_FUNC(menu_sub, 1);
|
1020
|
+
MENU_SNG_FUNC(menu_spacing, 4);
|
1021
|
+
MENU_SNG_FUNC(menu_term, 1);
|
1022
|
+
/* MENU_SNG_FUNC(menu_userptr, 1); */
|
1023
|
+
MENU_SNG_FUNC(menu_win, 1);
|
1024
|
+
MENU_SNG_FUNC(new_item, 2);
|
1025
|
+
MENU_SNG_FUNC(new_menu, 1);
|
1026
|
+
MENU_SNG_FUNC(pos_menu_cursor, 1);
|
1027
|
+
MENU_SNG_FUNC(post_menu, 1);
|
1028
|
+
MENU_SNG_FUNC(scale_menu, 3);
|
1029
|
+
MENU_SNG_FUNC(set_current_item, 2);
|
1030
|
+
MENU_SNG_FUNC(set_item_init, 2);
|
1031
|
+
MENU_SNG_FUNC(set_item_opts, 2);
|
1032
|
+
MENU_SNG_FUNC(set_item_term, 2);
|
1033
|
+
/* MENU_SNG_FUNC(set_item_userptr, 2); */
|
1034
|
+
MENU_SNG_FUNC(set_item_value, 2);
|
1035
|
+
MENU_SNG_FUNC(set_menu_back, 2);
|
1036
|
+
MENU_SNG_FUNC(set_menu_fore, 2);
|
1037
|
+
MENU_SNG_FUNC(set_menu_format, 3);
|
1038
|
+
MENU_SNG_FUNC(set_menu_grey, 2);
|
1039
|
+
MENU_SNG_FUNC(set_menu_init, 2);
|
1040
|
+
MENU_SNG_FUNC(set_menu_items, 2);
|
1041
|
+
MENU_SNG_FUNC(set_menu_mark, 2);
|
1042
|
+
MENU_SNG_FUNC(set_menu_opts, 2);
|
1043
|
+
MENU_SNG_FUNC(set_menu_pad, 2);
|
1044
|
+
MENU_SNG_FUNC(set_menu_pattern, 2);
|
1045
|
+
MENU_SNG_FUNC(set_menu_sub, 2);
|
1046
|
+
MENU_SNG_FUNC(set_menu_spacing, 4);
|
1047
|
+
MENU_SNG_FUNC(set_menu_term, 2);
|
1048
|
+
/* MENU_SNG_FUNC(set_menu_userptr, 2); */
|
1049
|
+
MENU_SNG_FUNC(set_menu_win, 2);
|
1050
|
+
MENU_SNG_FUNC(set_top_row, 2);
|
1051
|
+
MENU_SNG_FUNC(top_row, 1);
|
1052
|
+
MENU_SNG_FUNC(unpost_menu, 1);
|
1053
|
+
|
1054
|
+
init_menu_err_codes();
|
1055
|
+
init_menu_req_constants();
|
1056
|
+
init_menu_opts_constants();
|
1057
|
+
init_item_opts_constants();
|
1058
|
+
|
1059
|
+
/* Hashes to store registered blocks (Proc) */
|
1060
|
+
{
|
1061
|
+
VALUE hashes = rb_iv_set(mMenu, "@proc_hashes", rb_ary_new());
|
1062
|
+
int i;
|
1063
|
+
|
1064
|
+
for (i = 0; i < PROC_HASHES_COUNT; i++)
|
1065
|
+
rb_ary_push(hashes, rb_hash_new());
|
1066
|
+
}
|
1067
|
+
|
1068
|
+
/* Menus */
|
1069
|
+
rb_iv_set(mMenu, "@menus_hash", rb_hash_new());
|
1070
|
+
cMENU = rb_define_class_under(mMenu, "MENU", rb_cObject);
|
1071
|
+
rb_define_singleton_method(cMENU, "new", (&rbncurs_m_new_menu), 1);
|
1072
|
+
|
1073
|
+
RB_CLASS_METH(cMENU, NULL, current_item, 0);
|
1074
|
+
RB_CLASS_METH(cMENU, "free", free_menu, 0);
|
1075
|
+
RB_CLASS_METH(cMENU, NULL, item_count, 0);
|
1076
|
+
RB_CLASS_METH(cMENU, NULL, item_init, 0);
|
1077
|
+
RB_CLASS_METH(cMENU, NULL, item_term, 0);
|
1078
|
+
RB_CLASS_METH(cMENU, "back", menu_back, 0);
|
1079
|
+
RB_CLASS_METH(cMENU, "driver", menu_driver, 1);
|
1080
|
+
RB_CLASS_METH(cMENU, "fore", menu_fore, 0);
|
1081
|
+
RB_CLASS_METH(cMENU, "format", menu_format, 2);
|
1082
|
+
RB_CLASS_METH(cMENU, "grey", menu_grey, 0);
|
1083
|
+
RB_CLASS_METH(cMENU, "init", menu_init, 0);
|
1084
|
+
RB_CLASS_METH(cMENU, "items", menu_items, 0);
|
1085
|
+
RB_CLASS_METH(cMENU, "mark", menu_mark, 0);
|
1086
|
+
RB_CLASS_METH(cMENU, "opts", menu_opts, 0);
|
1087
|
+
RB_CLASS_METH(cMENU, "opts_off", menu_opts_off, 1);
|
1088
|
+
RB_CLASS_METH(cMENU, "opts_on", menu_opts_on, 1);
|
1089
|
+
RB_CLASS_METH(cMENU, "pad", menu_pad, 0);
|
1090
|
+
RB_CLASS_METH(cMENU, "pattern", menu_pattern, 0);
|
1091
|
+
RB_CLASS_METH(cMENU, "sub", menu_sub, 0);
|
1092
|
+
RB_CLASS_METH(cMENU, "spacing", menu_spacing, 3);
|
1093
|
+
RB_CLASS_METH(cMENU, "term", menu_term, 0);
|
1094
|
+
/* RB_CLASS_METH(cMENU, "userptr", menu_userptr, 0); */
|
1095
|
+
RB_CLASS_METH(cMENU, "win", menu_win, 0);
|
1096
|
+
RB_CLASS_METH(cMENU, "pos_cursor", pos_menu_cursor, 0);
|
1097
|
+
RB_CLASS_METH(cMENU, "post", post_menu, 0);
|
1098
|
+
RB_CLASS_METH(cMENU, "scale", scale_menu, 2);
|
1099
|
+
RB_CLASS_METH(cMENU, "current_item=", set_current_item, 1);
|
1100
|
+
RB_CLASS_METH(cMENU, "item_init=", set_item_init, 1);
|
1101
|
+
RB_CLASS_METH(cMENU, "item_term=", set_item_term, 1);
|
1102
|
+
RB_CLASS_METH(cMENU, "back=", set_menu_back, 1);
|
1103
|
+
RB_CLASS_METH(cMENU, "fore=", set_menu_fore, 1);
|
1104
|
+
RB_CLASS_METH(cMENU, "set_format", set_menu_format, 2);
|
1105
|
+
RB_CLASS_METH(cMENU, "grey=", set_menu_grey, 1);
|
1106
|
+
RB_CLASS_METH(cMENU, "init=", set_menu_init, 1);
|
1107
|
+
RB_CLASS_METH(cMENU, "items=", set_menu_items, 1);
|
1108
|
+
RB_CLASS_METH(cMENU, "mark=", set_menu_mark, 1);
|
1109
|
+
RB_CLASS_METH(cMENU, "opts=", set_menu_opts, 1);
|
1110
|
+
RB_CLASS_METH(cMENU, "pad=", set_menu_pad, 1);
|
1111
|
+
RB_CLASS_METH(cMENU, "pattern=", set_menu_pattern, 1);
|
1112
|
+
RB_CLASS_METH(cMENU, "sub=", set_menu_sub, 1);
|
1113
|
+
RB_CLASS_METH(cMENU, "set_spacing", set_menu_spacing, 3);
|
1114
|
+
RB_CLASS_METH(cMENU, "term=", set_menu_term, 1);
|
1115
|
+
/* RB_CLASS_METH(cMENU, "userptr=", set_menu_userptr, 1); */
|
1116
|
+
RB_CLASS_METH(cMENU, "win=", set_menu_win, 1);
|
1117
|
+
RB_CLASS_METH(cMENU, "top_row=", set_top_row, 1);
|
1118
|
+
RB_CLASS_METH(cMENU, NULL, top_row, 0);
|
1119
|
+
RB_CLASS_METH(cMENU, "unpost", unpost_menu, 0);
|
1120
|
+
|
1121
|
+
/* Items */
|
1122
|
+
rb_iv_set(mMenu, "@items_hash", rb_hash_new());
|
1123
|
+
cITEM = rb_define_class_under(mMenu, "ITEM", rb_cObject);
|
1124
|
+
rb_define_singleton_method(cITEM, "new", (&rbncurs_m_new_item), 2);
|
1125
|
+
|
1126
|
+
RB_CLASS_METH(cITEM, "free", free_item, 0);
|
1127
|
+
RB_CLASS_METH(cITEM, "description", item_description, 0);
|
1128
|
+
RB_CLASS_METH(cITEM, "index", item_index, 0);
|
1129
|
+
RB_CLASS_METH(cITEM, "name", item_name, 0);
|
1130
|
+
RB_CLASS_METH(cITEM, "opts", item_opts, 0);
|
1131
|
+
RB_CLASS_METH(cITEM, "opts_off", item_opts_off, 1);
|
1132
|
+
RB_CLASS_METH(cITEM, "opts_on", item_opts_on, 1);
|
1133
|
+
/* RB_CLASS_METH(cITEM, "userptr", item_userptr, 0); */
|
1134
|
+
RB_CLASS_METH(cITEM, "value", item_value, 0);
|
1135
|
+
RB_CLASS_METH(cITEM, "visible?", item_visible, 0);
|
1136
|
+
RB_CLASS_METH(cITEM, "opts=", set_item_opts, 1);
|
1137
|
+
/* RB_CLASS_METH(cITEM, "userptr=", set_item_userptr, 1); */
|
1138
|
+
RB_CLASS_METH(cITEM, "value=", set_item_value, 1);
|
1139
|
+
}
|
1140
|
+
|
1141
|
+
#endif
|