Data
def initialize(h, w, top, left)
static VALUE
window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left)
{
struct windata *winp;
WINDOW *window;
rb_secure(4);
curses_init_screen();
Data_Get_Struct(obj, struct windata, winp);
if (winp->window) delwin(winp->window);
window = newwin(NUM2INT(h), NUM2INT(w), NUM2INT(top), NUM2INT(left));
wclear(window);
winp->window = window;
return obj;
}
def <<(str)
static VALUE
window_addstr2(VALUE obj, VALUE str)
{
window_addstr(obj, str);
return obj;
}
def addch(ch)
static VALUE
window_addch(VALUE obj, VALUE ch)
{
struct windata *winp;
GetWINDOW(obj, winp);
waddch(winp->window, NUM2CH(ch));
return Qnil;
}
def addstr(str)
static VALUE
window_addstr(VALUE obj, VALUE str)
{
if (!NIL_P(str)) {
struct windata *winp;
StringValue(str);
str = rb_str_export_locale(str);
GetWINDOW(obj, winp);
waddstr(winp->window, StringValueCStr(str));
}
return Qnil;
}
static VALUE
window_attroff(VALUE obj, VALUE attrs)
{
#ifdef HAVE_WATTROFF
struct windata *winp;
GetWINDOW(obj,winp);
return INT2FIX(wattroff(winp->window,NUM2INT(attrs)));
#else
return Qtrue;
#endif
}
static VALUE
window_attron(VALUE obj, VALUE attrs)
{
#ifdef HAVE_WATTRON
struct windata *winp;
VALUE val;
GetWINDOW(obj,winp);
val = INT2FIX(wattron(winp->window,NUM2INT(attrs)));
if (rb_block_given_p()) {
rb_yield(val);
wattroff(winp->window,NUM2INT(attrs));
return val;
}
else{
return val;
}
#else
return Qtrue;
#endif
}
static VALUE
window_attrset(VALUE obj, VALUE attrs)
{
#ifdef HAVE_WATTRSET
struct windata *winp;
GetWINDOW(obj,winp);
return INT2FIX(wattrset(winp->window,NUM2INT(attrs)));
#else
return Qtrue;
#endif
}
def begx
static VALUE
window_begx(VALUE obj)
{
struct windata *winp;
int x, y;
GetWINDOW(obj, winp);
#ifdef getbegyx
getbegyx(winp->window, y, x);
return INT2FIX(x);
#else
return INT2FIX(winp->window->_begx);
#endif
}
def begy
static VALUE
window_begy(VALUE obj)
{
struct windata *winp;
int x, y;
GetWINDOW(obj, winp);
#ifdef getbegyx
getbegyx(winp->window, y, x);
return INT2FIX(y);
#else
return INT2FIX(winp->window->_begy);
#endif
}
static VALUE
window_bkgd(VALUE obj, VALUE ch)
{
#ifdef HAVE_WBKGD
struct windata *winp;
GetWINDOW(obj,winp);
return (wbkgd(winp->window, NUM2CH(ch)) == OK) ? Qtrue : Qfalse;
#else
return Qfalse;
#endif
}
static VALUE
window_bkgdset(VALUE obj, VALUE ch)
{
#ifdef HAVE_WBKGDSET
struct windata *winp;
GetWINDOW(obj,winp);
wbkgdset(winp->window, NUM2CH(ch));
#endif
return Qnil;
}
def box(vert, hor)
static VALUE
window_box(int argc, VALUE *argv, VALUE self)
{
struct windata *winp;
VALUE vert, hor, corn;
rb_scan_args(argc, argv, "21", &vert, &hor, &corn);
GetWINDOW(self, winp);
box(winp->window, NUM2CH(vert), NUM2CH(hor));
if (!NIL_P(corn)) {
int cur_x, cur_y, x, y;
chtype c;
c = NUM2CH(corn);
getyx(winp->window, cur_y, cur_x);
x = NUM2INT(window_maxx(self)) - 1;
y = NUM2INT(window_maxy(self)) - 1;
wmove(winp->window, 0, 0);
waddch(winp->window, c);
wmove(winp->window, y, 0);
waddch(winp->window, c);
wmove(winp->window, y, x);
waddch(winp->window, c);
wmove(winp->window, 0, x);
waddch(winp->window, c);
wmove(winp->window, cur_y, cur_x);
}
return Qnil;
}
def clear
static VALUE
window_clear(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wclear(winp->window);
return Qnil;
}
def close
static VALUE
window_close(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
delwin(winp->window);
winp->window = 0;
return Qnil;
}
def clrtoeol
static VALUE
window_clrtoeol(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wclrtoeol(winp->window);
return Qnil;
}
static VALUE
window_color_set(VALUE obj, VALUE col)
{
struct windata *winp;
int res;
GetWINDOW(obj, winp);
res = wcolor_set(winp->window, NUM2INT(col), NULL);
return (res == OK) ? Qtrue : Qfalse;
}
def curx
static VALUE
window_curx(VALUE obj)
{
struct windata *winp;
int x, y;
GetWINDOW(obj, winp);
getyx(winp->window, y, x);
return INT2FIX(x);
}
def cury
static VALUE
window_cury(VALUE obj)
{
struct windata *winp;
int x, y;
GetWINDOW(obj, winp);
getyx(winp->window, y, x);
return INT2FIX(y);
}
def delch
static VALUE
window_delch(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wdelch(winp->window);
return Qnil;
}
def delelteln
static VALUE
window_deleteln(VALUE obj)
{
#if defined(HAVE_WDELETELN) || defined(wdeleteln)
struct windata *winp;
GetWINDOW(obj, winp);
wdeleteln(winp->window);
#endif
return Qnil;
}
static VALUE
window_getbkgd(VALUE obj)
{
#ifdef HAVE_WGETBKGD
chtype c;
struct windata *winp;
GetWINDOW(obj,winp);
return (c = getbkgd(winp->window) != ERR) ? CH2FIX(c) : Qnil;
#else
return Qnil;
#endif
}
def getch
static VALUE
window_getch(VALUE obj)
{
struct windata *winp;
struct wgetch_arg arg;
int c;
GetWINDOW(obj, winp);
arg.win = winp->window;
rb_thread_blocking_region(wgetch_func, (void *)&arg, RUBY_UBF_IO, 0);
c = arg.c;
if (c == EOF) return Qnil;
if (rb_isprint(c)) {
char ch = (char)c;
return rb_locale_str_new(&ch, 1);
}
return UINT2NUM(c);
}
def getstr
static VALUE
window_getstr(VALUE obj)
{
struct windata *winp;
struct wgetstr_arg arg;
GetWINDOW(obj, winp);
arg.win = winp->window;
rb_thread_blocking_region(wgetstr_func, (void *)&arg, RUBY_UBF_IO, 0);
return rb_locale_str_new_cstr(arg.rtn);
}
static VALUE
window_idlok(VALUE obj, VALUE bf)
{
struct windata *winp;
GetWINDOW(obj, winp);
idlok(winp->window, RTEST(bf) ? TRUE : FALSE);
return Qnil;
}
def inch
static VALUE
window_inch(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
return CH2FIX(winch(winp->window));
}
def insch(ch)
static VALUE
window_insch(VALUE obj, VALUE ch)
{
struct windata *winp;
GetWINDOW(obj, winp);
winsch(winp->window, NUM2CH(ch));
return Qnil;
}
def insertln
static VALUE
window_insertln(VALUE obj)
{
#if defined(HAVE_WINSERTLN) || defined(winsertln)
struct windata *winp;
GetWINDOW(obj, winp);
winsertln(winp->window);
#endif
return Qnil;
}
static VALUE
window_keypad(VALUE obj, VALUE val)
{
struct windata *winp;
GetWINDOW(obj,winp);
/* keypad() of NetBSD's libcurses returns no value */
#if defined(__NetBSD__) && !defined(NCURSES_VERSION)
keypad(winp->window,(RTEST(val) ? TRUE : FALSE));
return Qnil;
#else
/* may have to raise exception on ERR */
return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ?
Qtrue : Qfalse;
#endif
}
static VALUE
window_keypad(VALUE obj, VALUE val)
{
struct windata *winp;
GetWINDOW(obj,winp);
/* keypad() of NetBSD's libcurses returns no value */
#if defined(__NetBSD__) && !defined(NCURSES_VERSION)
keypad(winp->window,(RTEST(val) ? TRUE : FALSE));
return Qnil;
#else
/* may have to raise exception on ERR */
return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ?
Qtrue : Qfalse;
#endif
}
def maxx
static VALUE
window_maxx(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
#if defined(getmaxx)
return INT2FIX(getmaxx(winp->window));
#elif defined(getmaxyx)
{
int x, y;
getmaxyx(winp->window, y, x);
return INT2FIX(x);
}
#else
return INT2FIX(winp->window->_maxx+1);
#endif
}
def maxy
static VALUE
window_maxy(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
#if defined(getmaxy)
return INT2FIX(getmaxy(winp->window));
#elif defined(getmaxyx)
{
int x, y;
getmaxyx(winp->window, y, x);
return INT2FIX(y);
}
#else
return INT2FIX(winp->window->_maxy+1);
#endif
}
def move(y, x)
static VALUE
window_move(VALUE obj, VALUE y, VALUE x)
{
struct windata *winp;
GetWINDOW(obj, winp);
mvwin(winp->window, NUM2INT(y), NUM2INT(x));
return Qnil;
}
static VALUE
window_nodelay(VALUE obj, VALUE val)
{
struct windata *winp;
GetWINDOW(obj,winp);
/* nodelay() of NetBSD's libcurses returns no value */
#if defined(__NetBSD__) && !defined(NCURSES_VERSION)
nodelay(winp->window, RTEST(val) ? TRUE : FALSE);
return Qnil;
#else
return nodelay(winp->window,RTEST(val) ? TRUE : FALSE) == OK ? Qtrue : Qfalse;
#endif
}
def noutrefresh
static VALUE
window_noutrefresh(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
#ifdef HAVE_DOUPDATE
wnoutrefresh(winp->window);
#else
wrefresh(winp->window);
#endif
return Qnil;
}
def refresh
static VALUE
window_refresh(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wrefresh(winp->window);
return Qnil;
}
static VALUE
window_resize(VALUE obj, VALUE lin, VALUE col)
{
#if defined(HAVE_WRESIZE)
struct windata *winp;
GetWINDOW(obj,winp);
return wresize(winp->window, NUM2INT(lin), NUM2INT(col)) == OK ? Qtrue : Qfalse;
#else
return Qnil;
#endif
}
static VALUE
window_scrl(VALUE obj, VALUE n)
{
#ifdef HAVE_WSCRL
struct windata *winp;
GetWINDOW(obj, winp);
/* may have to raise exception on ERR */
return (wscrl(winp->window,NUM2INT(n)) == OK) ? Qtrue : Qfalse;
#else
return Qfalse;
#endif
}
defined(USE_COLOR) && defined(HAVE_WCOLOR_SET)
static VALUE
window_scroll(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
/* may have to raise exception on ERR */
return (scroll(winp->window) == OK) ? Qtrue : Qfalse;
}
static VALUE
window_scrollok(VALUE obj, VALUE bf)
{
struct windata *winp;
GetWINDOW(obj, winp);
scrollok(winp->window, RTEST(bf) ? TRUE : FALSE);
return Qnil;
}
def setpos(y, x)
static VALUE
window_setpos(VALUE obj, VALUE y, VALUE x)
{
struct windata *winp;
GetWINDOW(obj, winp);
wmove(winp->window, NUM2INT(y), NUM2INT(x));
return Qnil;
}
static VALUE
window_setscrreg(VALUE obj, VALUE top, VALUE bottom)
{
#ifdef HAVE_WSETSCRREG
struct windata *winp;
int res;
GetWINDOW(obj, winp);
res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom));
/* may have to raise exception on ERR */
return (res == OK) ? Qtrue : Qfalse;
#else
return Qfalse;
#endif
}
def standend
static VALUE
window_standend(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wstandend(winp->window);
return Qnil;
}
def standout
static VALUE
window_standout(VALUE obj)
{
struct windata *winp;
GetWINDOW(obj, winp);
wstandout(winp->window);
return Qnil;
}
def subwin(height, width, top, left)
static VALUE
window_subwin(VALUE obj, VALUE height, VALUE width, VALUE top, VALUE left)
{
struct windata *winp;
WINDOW *window;
VALUE win;
int h, w, t, l;
h = NUM2INT(height);
w = NUM2INT(width);
t = NUM2INT(top);
l = NUM2INT(left);
GetWINDOW(obj, winp);
window = subwin(winp->window, h, w, t, l);
win = prep_window(rb_obj_class(obj), window);
return win;
}