snowleopard-ncurses 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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(StringValuePtr(name), StringValuePtr(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(StringValuePtr(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, StringValuePtr(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, StringValuePtr(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