50 #include <ncursesw/term.h>
54 #define YUILogComponent "ncurses"
55 #include <yui/YUILog.h>
56 #include <yui/YUIException.h>
62 #define COLORS_NEED_INITIALIZATION -1
63 #define COLORS_NOT_INITIALIZED 0
64 #define COLORS_MONOCHROME 1
65 #define COLORS_ARE_REALLY_THERE 2
71 bool NCursesWindow::b_initialized = FALSE;
79 va_start( args, fmt );
81 vsprintf( buf, fmt, args );
83 return waddstr(
w, buf );
91 va_start( args, fmt );
92 int result = wmove(
w, y, x );
97 vsprintf( buf, fmt, args );
98 result = waddstr(
w, buf );
109 const std::wstring wstr( str );
112 if ( NCstring::terminalEncoding() !=
"UTF-8" )
114 NCstring::RecodeFromWchar( wstr, NCstring::terminalEncoding(), &out );
115 return ::mvwaddnstr(
w, y, x, out.c_str(), n );
118 return ::mvwaddnwstr(
w, y, x, (
wchar_t *) str, n );
126 const std::wstring wstr( str );
129 if ( NCstring::terminalEncoding() !=
"UTF-8" )
131 NCstring::RecodeFromWchar( wstr, NCstring::terminalEncoding(), &out );
132 return ::waddnstr(
w, out.c_str(), n );
135 return ::waddnwstr(
w, (
wchar_t *) str, n );
142 int ret = mvwin_wch(
w, y, x, combined );
143 combined->attr = combined->attr & ( A_CHARTEXT | A_ALTCHARSET );
147 #ifdef NCURSES_EXT_COLORS
148 combined->ext_color = 0;
156 int ret = win_wch(
w, combined );
157 combined->attr = combined->attr & ( A_CHARTEXT | A_ALTCHARSET );
160 #ifdef NCURSES_EXT_COLORS
161 combined->ext_color = 0;
171 if ( NCstring::terminalEncoding() !=
"UTF-8" )
173 ret =
addch( inchar( y, x ) );
190 NCursesWindow::add_attr_char()
194 if ( NCstring::terminalEncoding() !=
"UTF-8" )
196 ret =
addch( inchar() );
213 NCursesWindow::init(
void )
220 if (!env && (env = ::getenv(
"TERM"))) {
221 if (::strncmp(env,
"linux", 5) == 0)
222 back_color_erase = FALSE;
233 THROW(
new NCursesException( msg ) );
237 NCursesWindow::initialize()
239 if ( !b_initialized )
242 b_initialized = TRUE;
244 if ( colorInitialized == COLORS_NEED_INITIALIZATION )
246 colorInitialized = COLORS_NOT_INITIALIZED;
257 : w(0), alloced(FALSE), par(0), subwins(0), sib(0)
259 if ( !b_initialized )
262 w =
static_cast<WINDOW *
>(0);
270 : w(0), alloced(TRUE), par(0), subwins(0), sib(0)
272 if ( !b_initialized )
289 w = ::newwin(
lines,
cols, begin_y, begin_x );
302 : w(0), alloced(FALSE), par(0), subwins(0), sib(0)
304 if ( !b_initialized )
307 w = window ? window : ::stdscr;
315 int begin_y,
int begin_x,
char absrel )
316 : w(0), alloced(TRUE), par(0), subwins(0), sib(0)
332 begin_y -= win.
begy();
333 begin_x -= win.
begx();
336 if ( l + begin_y > win.
height() )
337 l = win.
height() - begin_y;
339 if ( c + begin_x > win.
width() )
340 c = win.
width() - begin_x;
346 w = ::derwin( win.
w, l, c, begin_y, begin_x );
350 yuiError() <<
"NULL subwindow; throw " <<
wpos( begin_y, begin_x ) <<
wsze( l, c ) << std::endl;
351 YUI_THROW( YUIException(
"NULL ncurses lowlevel subwindow" ) );
364 WINDOW *d = ::dupwin(
w );
374 static RIPOFFINIT R_INIT[5];
375 static int r_init_idx = 0;
376 static RIPOFFINIT* prip = R_INIT;
382 assert((
w->_maxx + 1 ) ==
cols );
387 int NCursesWindow::ripoff_init( WINDOW *w,
int cols )
391 RIPOFFINIT init = *prip++;
407 if ( code == OK && init && ripoff_lines )
409 R_INIT[r_init_idx++] = init;
424 if ( p->isDescendant( win ) )
437 p->kill_subwindows();
465 else if ( win ==
this )
493 else if (
count < 0 )
502 int NCursesWindow::colorInitialized = COLORS_NOT_INITIALIZED;
507 if ( colorInitialized == COLORS_NOT_INITIALIZED )
511 if ( ::has_colors() )
514 colorInitialized = COLORS_ARE_REALLY_THERE;
517 colorInitialized = COLORS_MONOCHROME;
520 colorInitialized = COLORS_NEED_INITIALIZATION;
529 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
531 if ( pair_content( PAIR_NUMBER(
w->_attrs ), &fore, &back ) )
541 return getback ? back : fore;
546 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
555 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
556 return PAIR_NUMBER(
w->_attrs );
562 NCursesWindow::setpalette(
short fore,
short back,
short pair )
564 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
565 return init_pair( pair, fore, back );
571 NCursesWindow::setpalette(
short fore,
short back )
573 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
574 return setpalette( fore, back, PAIR_NUMBER(
w->_attrs ) );
582 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
584 if (( pair < 1 ) || ( pair > COLOR_PAIRS ) )
597 return (( ::has_key( KEY_MOUSE ) || ::
has_mouse() )
601 NCursesPad::NCursesPad(
int lines,
int cols ) :
NCursesWindow()
611 if (
w == ( WINDOW* )0 )
624 wrect box_area( dim.intersectRelTo( area() ) );
626 if ( box_area.Sze > 0 )
628 hline( box_area.Pos.L, box_area.Pos.C, box_area.Sze.W );
629 hline( box_area.Pos.L + box_area.Sze.H - 1, box_area.Pos.C, box_area.Sze.W );
630 vline( box_area.Pos.L, box_area.Pos.C, box_area.Sze.H );
631 vline( box_area.Pos.L, box_area.Pos.C + box_area.Sze.W - 1, box_area.Sze.H );
633 addch( box_area.Pos.L + box_area.Sze.H - 1, box_area.Pos.C, ACS_LLCORNER );
634 addch( box_area.Pos.L, box_area.Pos.C + box_area.Sze.W - 1, ACS_URCORNER );
635 addch( box_area.Pos.L + box_area.Sze.H - 1, box_area.Pos.C + box_area.Sze.W - 1, ACS_LRCORNER );
636 addch( box_area.Pos.L, box_area.Pos.C, ACS_ULCORNER );
645 int NCursesWindow::mvsubwin(
NCursesWindow * sub,
int begin_y,
int begin_x )
649 if ( sub && sub->
parent() )
652 ret = ::mvderwin( sub->
w, begin_y, begin_x );
656 ret = mvsubwin( ch, ch->w->_pary, ch->w->_parx );
665 int NCursesWindow::resize(
int lines,
int columns )
673 return ::wresize(
w,
lines, columns );
677 std::ostream & operator<<( std::ostream & Stream,
const NCursesWindow * Obj_Cv )
680 return Stream << *Obj_Cv;
682 return Stream <<
"(NoNCWin)";
686 std::ostream & operator<<( std::ostream & Stream,
const NCursesWindow & Obj_Cv )
688 return Stream <<
"NCWin(" << Obj_Cv.
w