sup

A curses threads-with-tags style email client

ncursesw-ruby.git

git clone https://supmua.dev/git/ncursesw-ruby/

menu_wrap.c (35869B) - raw

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