8282# define USE_MOUSE 1
8383#endif
8484
85- #define NUM2CH NUM2CHR
86- #define CH2FIX CHR2FIX
87-
8885#define OBJ2CHTYPE rb_obj2chtype_inline
8986
9087static inline chtype
9188rb_obj2chtype_inline (VALUE x )
9289{
93- if (RB_TYPE_P (x , RUBY_T_STRING ) && (RSTRING_LEN (x )>=1 ))
94- return RSTRING_PTR (x )[0 ];
95- else
96- return NUM2CHTYPE (x );
90+ if (RB_TYPE_P (x , RUBY_T_STRING )) {
91+ ID id_ord ;
92+
93+ CONST_ID (id_ord , "ord" );
94+ x = rb_funcall (x , id_ord , 0 );
95+ }
96+ return NUM2CHTYPE (x );
9797}
9898
9999static VALUE mCurses ;
@@ -302,7 +302,7 @@ static void curses_finalize(VALUE);
302302 * see also Curses.stdscr
303303 */
304304static VALUE
305- curses_init_screen (void )
305+ curses_init_screen (VALUE self )
306306{
307307 if (rb_stdscr ) return rb_stdscr ;
308308 initscr ();
@@ -325,7 +325,7 @@ curses_init_screen(void)
325325 *
326326 * Many curses functions use this window.
327327 */
328- #define curses_stdscr curses_init_screen
328+ #define curses_stdscr () curses_init_screen(Qnil)
329329
330330/*
331331 * Document-method: Curses.close_screen
@@ -341,7 +341,7 @@ curses_init_screen(void)
341341 *
342342 */
343343static VALUE
344- curses_close_screen (void )
344+ curses_close_screen (VALUE self )
345345{
346346 curses_stdscr ();
347347#ifdef HAVE_ISENDWIN
@@ -381,7 +381,7 @@ curses_finalize(VALUE dummy)
381381 * returns +false+ otherwise.
382382 */
383383static VALUE
384- curses_closed (void )
384+ curses_closed (VALUE self )
385385{
386386 curses_stdscr ();
387387 if (isendwin ()) {
@@ -431,7 +431,7 @@ curses_erase(VALUE obj)
431431 * Clears to the end of line, that the cursor is currently on.
432432 */
433433static VALUE
434- curses_clrtoeol (void )
434+ curses_clrtoeol (VALUE self )
435435{
436436 curses_stdscr ();
437437 clrtoeol ();
@@ -758,7 +758,7 @@ static VALUE
758758curses_inch (VALUE obj )
759759{
760760 curses_stdscr ();
761- return CH2FIX (inch ());
761+ return CHTYPE2NUM (inch ());
762762}
763763
764764/*
@@ -960,7 +960,7 @@ curses_keyname(VALUE obj, VALUE c)
960960 * Returns the number of lines on the screen
961961 */
962962static VALUE
963- curses_lines (void )
963+ curses_lines (VALUE self )
964964{
965965 return INT2FIX (LINES );
966966}
@@ -971,7 +971,7 @@ curses_lines(void)
971971 * Returns the number of columns on the screen
972972 */
973973static VALUE
974- curses_cols (void )
974+ curses_cols (VALUE self )
975975{
976976 return INT2FIX (COLS );
977977}
@@ -1117,7 +1117,7 @@ curses_bkgdset(VALUE obj, VALUE ch)
11171117{
11181118#ifdef HAVE_BKGDSET
11191119 curses_stdscr ();
1120- bkgdset (NUM2CHTYPE (ch ));
1120+ bkgdset (OBJ2CHTYPE (ch ));
11211121#endif
11221122 return Qnil ;
11231123}
@@ -1138,7 +1138,7 @@ curses_bkgd(VALUE obj, VALUE ch)
11381138{
11391139#ifdef HAVE_BKGD
11401140 curses_stdscr ();
1141- return (bkgd (NUM2CHTYPE (ch )) == OK ) ? Qtrue : Qfalse ;
1141+ return (bkgd (OBJ2CHTYPE (ch )) == OK ) ? Qtrue : Qfalse ;
11421142#else
11431143 return Qfalse ;
11441144#endif
@@ -1559,7 +1559,7 @@ static VALUE
15591559curses_mousemask (VALUE obj , VALUE mask )
15601560{
15611561 curses_stdscr ();
1562- return INT2NUM (mousemask (NUM2UINT (mask ),NULL ));
1562+ return ULONG2NUM (mousemask (NUM2UINT (mask ),NULL ));
15631563}
15641564
15651565#define DEFINE_MOUSE_GET_MEMBER (func_name ,mem ) \
@@ -1600,7 +1600,12 @@ DEFINE_MOUSE_GET_MEMBER(curs_mouse_z, z)
16001600 * Returns the current mouse's button state. Use this with the button state
16011601 * constants to determine which buttons were pressed.
16021602 */
1603- DEFINE_MOUSE_GET_MEMBER (curs_mouse_bstate , bstate )
1603+ static VALUE curs_mouse_bstate (VALUE mouse )
1604+ {
1605+ struct mousedata * mdata ;
1606+ GetMOUSE (mouse , mdata );
1607+ return ULONG2NUM (mdata -> mevent -> bstate );
1608+ }
16041609#undef define_curs_mouse_member
16051610#endif /* USE_MOUSE */
16061611
@@ -1692,7 +1697,7 @@ window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left)
16921697 struct windata * winp ;
16931698 WINDOW * window ;
16941699
1695- curses_init_screen ();
1700+ curses_init_screen (Qnil );
16961701 TypedData_Get_Struct (obj , struct windata , & windata_type , winp );
16971702 if (winp -> window ) delwin (winp -> window );
16981703 window = newwin (NUM2INT (h ), NUM2INT (w ), NUM2INT (top ), NUM2INT (left ));
@@ -2189,7 +2194,7 @@ window_begx(VALUE obj)
21892194
21902195/*
21912196 * Document-method: Curses::Window.box
2192- * call-seq: box(vert, hor)
2197+ * call-seq: box(vert = nil , hor = nil, corn = nil )
21932198 *
21942199 * set the characters to frame the window in.
21952200 * The vertical +vert+ and horizontal +hor+ character.
@@ -2204,16 +2209,18 @@ window_box(int argc, VALUE *argv, VALUE self)
22042209 struct windata * winp ;
22052210 VALUE vert , hor , corn ;
22062211
2207- rb_scan_args (argc , argv , "21 " , & vert , & hor , & corn );
2212+ rb_scan_args (argc , argv , "03 " , & vert , & hor , & corn );
22082213
22092214 GetWINDOW (self , winp );
2210- box (winp -> window , NUM2CH (vert ), NUM2CH (hor ));
2215+ box (winp -> window ,
2216+ NIL_P (vert ) ? 0 : OBJ2CHTYPE (vert ),
2217+ NIL_P (hor ) ? 0 : OBJ2CHTYPE (hor ));
22112218
22122219 if (!NIL_P (corn )) {
22132220 int cur_x , cur_y , x , y ;
22142221 chtype c ;
22152222
2216- c = NUM2CH (corn );
2223+ c = OBJ2CHTYPE (corn );
22172224 getyx (winp -> window , cur_y , cur_x );
22182225 x = NUM2INT (window_maxx (self )) - 1 ;
22192226 y = NUM2INT (window_maxy (self )) - 1 ;
@@ -2280,7 +2287,7 @@ window_inch(VALUE obj)
22802287 struct windata * winp ;
22812288
22822289 GetWINDOW (obj , winp );
2283- return CH2FIX (winch (winp -> window ));
2290+ return CHTYPE2NUM (winch (winp -> window ));
22842291}
22852292
22862293/*
@@ -2297,7 +2304,7 @@ window_addch(VALUE obj, VALUE ch)
22972304 struct windata * winp ;
22982305
22992306 GetWINDOW (obj , winp );
2300- waddch (winp -> window , NUM2CHTYPE (ch ));
2307+ waddch (winp -> window , OBJ2CHTYPE (ch ));
23012308
23022309 return Qnil ;
23032310}
@@ -2315,7 +2322,7 @@ window_insch(VALUE obj, VALUE ch)
23152322 struct windata * winp ;
23162323
23172324 GetWINDOW (obj , winp );
2318- winsch (winp -> window , NUM2CH (ch ));
2325+ winsch (winp -> window , OBJ2CHTYPE (ch ));
23192326
23202327 return Qnil ;
23212328}
@@ -2743,7 +2750,7 @@ window_bkgdset(VALUE obj, VALUE ch)
27432750 struct windata * winp ;
27442751
27452752 GetWINDOW (obj ,winp );
2746- wbkgdset (winp -> window , NUM2CHTYPE (ch ));
2753+ wbkgdset (winp -> window , OBJ2CHTYPE (ch ));
27472754#endif
27482755 return Qnil ;
27492756}
@@ -2764,7 +2771,7 @@ window_bkgd(VALUE obj, VALUE ch)
27642771 struct windata * winp ;
27652772
27662773 GetWINDOW (obj ,winp );
2767- return (wbkgd (winp -> window , NUM2CHTYPE (ch )) == OK ) ? Qtrue : Qfalse ;
2774+ return (wbkgd (winp -> window , OBJ2CHTYPE (ch )) == OK ) ? Qtrue : Qfalse ;
27682775#else
27692776 return Qfalse ;
27702777#endif
@@ -2932,7 +2939,7 @@ pad_initialize(VALUE obj, VALUE h, VALUE w)
29322939 struct windata * padp ;
29332940 WINDOW * window ;
29342941
2935- curses_init_screen ();
2942+ curses_init_screen (Qnil );
29362943 TypedData_Get_Struct (obj , struct windata , & windata_type , padp );
29372944 if (padp -> window ) delwin (padp -> window );
29382945 window = newpad (NUM2INT (h ), NUM2INT (w ));
@@ -3103,7 +3110,7 @@ item_initialize(VALUE obj, VALUE name, VALUE description)
31033110{
31043111 struct itemdata * itemp ;
31053112
3106- curses_init_screen ();
3113+ curses_init_screen (Qnil );
31073114 TypedData_Get_Struct (obj , struct itemdata , & itemdata_type , itemp );
31083115 if (itemp -> item ) {
31093116 rb_raise (rb_eRuntimeError , "already initialized item" );
@@ -3316,7 +3323,7 @@ menu_initialize(VALUE obj, VALUE items)
33163323 ID id_new ;
33173324
33183325 Check_Type (items , T_ARRAY );
3319- curses_init_screen ();
3326+ curses_init_screen (Qnil );
33203327 TypedData_Get_Struct (obj , struct menudata , & menudata_type , menup );
33213328 if (menup -> menu ) {
33223329 rb_raise (rb_eRuntimeError , "already initialized menu" );
@@ -3772,7 +3779,7 @@ field_initialize(VALUE obj, VALUE height, VALUE width,
37723779{
37733780 struct fielddata * fieldp ;
37743781
3775- curses_init_screen ();
3782+ curses_init_screen (Qnil );
37763783 TypedData_Get_Struct (obj , struct fielddata , & fielddata_type , fieldp );
37773784 if (fieldp -> field ) {
37783785 rb_raise (rb_eRuntimeError , "already initialized field" );
@@ -4230,7 +4237,7 @@ form_initialize(VALUE obj, VALUE fields)
42304237 int i ;
42314238
42324239 Check_Type (fields , T_ARRAY );
4233- curses_init_screen ();
4240+ curses_init_screen (Qnil );
42344241 TypedData_Get_Struct (obj , struct formdata , & formdata_type , formp );
42354242 if (formp -> form ) {
42364243 rb_raise (rb_eRuntimeError , "already initialized form" );
@@ -4730,7 +4737,7 @@ Init_curses(void)
47304737 rb_define_module_function (mCurses , "init_screen" , curses_init_screen , 0 );
47314738 rb_define_module_function (mCurses , "close_screen" , curses_close_screen , 0 );
47324739 rb_define_module_function (mCurses , "closed?" , curses_closed , 0 );
4733- rb_define_module_function (mCurses , "stdscr" , curses_stdscr , 0 );
4740+ rb_define_module_function (mCurses , "stdscr" , curses_init_screen , 0 );
47344741 rb_define_module_function (mCurses , "refresh" , curses_refresh , 0 );
47354742 rb_define_module_function (mCurses , "doupdate" , curses_doupdate , 0 );
47364743 rb_define_module_function (mCurses , "clear" , curses_clear , 0 );
@@ -4870,7 +4877,7 @@ Init_curses(void)
48704877 * win.close
48714878 *
48724879 */
4873- cWindow = rb_define_class_under (mCurses , "Window" , rb_cData );
4880+ cWindow = rb_define_class_under (mCurses , "Window" , rb_cObject );
48744881 rb_define_alloc_func (cWindow , window_s_allocate );
48754882 rb_define_method (cWindow , "initialize" , window_initialize , 4 );
48764883 rb_define_method (cWindow , "subwin" , window_subwin , 4 );
@@ -4954,7 +4961,7 @@ Init_curses(void)
49544961#endif
49554962
49564963#ifdef HAVE_MENU
4957- cItem = rb_define_class_under (mCurses , "Item" , rb_cData );
4964+ cItem = rb_define_class_under (mCurses , "Item" , rb_cObject );
49584965 rb_define_alloc_func (cItem , item_s_allocate );
49594966 rb_define_method (cItem , "initialize" , item_initialize , 2 );
49604967 rb_define_method (cItem , "==" , item_eq , 1 );
@@ -4965,7 +4972,7 @@ Init_curses(void)
49654972 rb_define_method (cItem , "opts_off" , item_opts_off_m , 1 );
49664973 rb_define_method (cItem , "opts" , item_opts_m , 0 );
49674974
4968- cMenu = rb_define_class_under (mCurses , "Menu" , rb_cData );
4975+ cMenu = rb_define_class_under (mCurses , "Menu" , rb_cObject );
49694976 rb_define_alloc_func (cMenu , menu_s_allocate );
49704977 rb_define_method (cMenu , "initialize" , menu_initialize , 1 );
49714978 rb_define_method (cMenu , "post" , menu_post , 0 );
@@ -4988,7 +4995,7 @@ Init_curses(void)
49884995#endif
49894996
49904997#ifdef HAVE_FORM
4991- cField = rb_define_class_under (mCurses , "Field" , rb_cData );
4998+ cField = rb_define_class_under (mCurses , "Field" , rb_cObject );
49924999 rb_define_alloc_func (cField , field_s_allocate );
49935000 rb_define_method (cField , "initialize" , field_initialize , 6 );
49945001 rb_define_method (cField , "set_buffer" , field_set_buffer , 2 );
@@ -5015,7 +5022,7 @@ Init_curses(void)
50155022 rb_define_method (cField , "max=" , field_set_max , 1 );
50165023 rb_define_method (cField , "set_type" , field_set_type , -1 );
50175024
5018- cForm = rb_define_class_under (mCurses , "Form" , rb_cData );
5025+ cForm = rb_define_class_under (mCurses , "Form" , rb_cObject );
50195026 rb_define_alloc_func (cForm , form_s_allocate );
50205027 rb_define_method (cForm , "initialize" , form_initialize , 1 );
50215028 rb_define_method (cForm , "post" , form_post , 0 );
0 commit comments