50 #include <ncursesw/term.h>
54 #define YUILogComponent "ncurses"
55 #include <yui/YUILog.h>
61 #define COLORS_NEED_INITIALIZATION -1
62 #define COLORS_NOT_INITIALIZED 0
63 #define COLORS_MONOCHROME 1
64 #define COLORS_ARE_REALLY_THERE 2
70 bool NCursesWindow::b_initialized = FALSE;
78 va_start( args, fmt );
80 vsprintf( buf, fmt, args );
82 return waddstr(
w, buf );
90 va_start( args, fmt );
91 int result = wmove(
w, y, x );
96 vsprintf( buf, fmt, args );
97 result = waddstr(
w, buf );
108 const std::wstring wstr( str );
111 if ( NCstring::terminalEncoding() !=
"UTF-8" )
113 NCstring::RecodeFromWchar( wstr, NCstring::terminalEncoding(), &out );
114 return ::mvwaddnstr(
w, y, x, out.c_str(), n );
117 return ::mvwaddnwstr(
w, y, x, (
wchar_t* )str, n );
125 const std::wstring wstr( str );
128 if ( NCstring::terminalEncoding() !=
"UTF-8" )
130 NCstring::RecodeFromWchar( wstr, NCstring::terminalEncoding(), &out );
131 return ::waddnstr(
w, out.c_str(), n );
134 return ::waddnwstr(
w, (
wchar_t* )str, n );
141 int ret = mvwin_wch(
w, y, x, combined );
142 combined->attr = combined->attr & ( A_CHARTEXT | A_ALTCHARSET );
146 #ifdef NCURSES_EXT_COLORS
147 combined->ext_color = 0;
155 int ret = win_wch(
w, combined );
156 combined->attr = combined->attr & ( A_CHARTEXT | A_ALTCHARSET );
159 #ifdef NCURSES_EXT_COLORS
160 combined->ext_color = 0;
170 if ( NCstring::terminalEncoding() !=
"UTF-8" )
172 ret =
addch( inchar( y, x ) );
189 NCursesWindow::add_attr_char( )
193 if ( NCstring::terminalEncoding() !=
"UTF-8" )
195 ret =
addch( inchar() );
212 NCursesWindow::init(
void )
219 if (!env && (env = ::getenv(
"TERM"))) {
220 if (::strncmp(env,
"linux", 5) == 0)
221 back_color_erase = FALSE;
232 THROW(
new NCursesException( msg ) );
236 NCursesWindow::initialize()
238 if ( !b_initialized )
241 b_initialized = TRUE;
243 if ( colorInitialized == COLORS_NEED_INITIALIZATION )
245 colorInitialized = COLORS_NOT_INITIALIZED;
256 : w(0), alloced(FALSE), par(0), subwins(0), sib(0)
258 if ( !b_initialized )
261 w =
static_cast<WINDOW *
>(0);
269 : w(0), alloced(TRUE), par(0), subwins(0), sib(0)
271 if ( !b_initialized )
286 yuiDebug() <<
"Lines: " << lines <<
" Cols: " << cols <<
" y: " << begin_y <<
" x: " << begin_x << std::endl;
288 w = ::newwin( lines, cols, begin_y, begin_x );
301 : w(0), alloced(FALSE), par(0), subwins(0), sib(0)
303 if ( !b_initialized )
306 w = window ? window : ::stdscr;
314 int begin_y,
int begin_x,
char absrel )
315 : w(0), alloced(TRUE), par(0), subwins(0), sib(0)
331 begin_y -= win.
begy();
332 begin_x -= win.
begx();
335 if ( l + begin_y > win.
height() )
336 l = win.
height() - begin_y;
338 if ( c + begin_x > win.
width() )
339 c = win.
width() - begin_x;
345 w = ::derwin( win.
w, l, c, begin_y, begin_x );
349 yuiError() <<
"Throw " <<
wpos( begin_y, begin_x ) <<
wsze( l, c ) << std::endl;
366 WINDOW *d = ::dupwin(
w );
376 static RIPOFFINIT R_INIT[5];
377 static int r_init_idx = 0;
378 static RIPOFFINIT* prip = R_INIT;
380 extern "C" int _nc_ripoffline(
int,
int ( *init )( WINDOW*,
int ) );
385 assert((
w->_maxx + 1 ) == cols );
390 int NCursesWindow::ripoff_init( WINDOW *w,
int cols )
394 RIPOFFINIT init = *prip++;
408 int code = ::_nc_ripoffline( ripoff_lines, ripoff_init );
410 if ( code == OK && init && ripoff_lines )
412 R_INIT[r_init_idx++] = init;
427 if ( p->isDescendant( win ) )
440 p->kill_subwindows();
468 else if ( win ==
this )
496 else if (
count < 0 )
505 int NCursesWindow::colorInitialized = COLORS_NOT_INITIALIZED;
510 if ( colorInitialized == COLORS_NOT_INITIALIZED )
514 if ( ::has_colors() )
517 colorInitialized = COLORS_ARE_REALLY_THERE;
520 colorInitialized = COLORS_MONOCHROME;
523 colorInitialized = COLORS_NEED_INITIALIZATION;
532 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
534 if ( pair_content( PAIR_NUMBER( w->_attrs ), &fore, &back ) )
544 return getback ? back : fore;
549 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
558 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
559 return PAIR_NUMBER( w->_attrs );
565 NCursesWindow::setpalette(
short fore,
short back,
short pair )
567 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
568 return init_pair( pair, fore, back );
574 NCursesWindow::setpalette(
short fore,
short back )
576 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
577 return setpalette( fore, back, PAIR_NUMBER( w->_attrs ) );
586 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
588 if (( pair < 1 ) || ( pair > COLOR_PAIRS ) )
599 extern "C" int _nc_has_mouse(
void );
603 return (( ::has_key( KEY_MOUSE ) || ::_nc_has_mouse() )
607 NCursesPad::NCursesPad(
int lines,
int cols ) :
NCursesWindow()
615 w = ::newpad( lines, cols );
617 if ( w == ( WINDOW* )0 )
630 wrect box_area( dim.intersectRelTo( area() ) );
632 if ( box_area.Sze > 0 )
634 hline( box_area.Pos.L, box_area.Pos.C, box_area.Sze.W );
635 hline( box_area.Pos.L + box_area.Sze.H - 1, box_area.Pos.C, box_area.Sze.W );
636 vline( box_area.Pos.L, box_area.Pos.C, box_area.Sze.H );
637 vline( box_area.Pos.L, box_area.Pos.C + box_area.Sze.W - 1, box_area.Sze.H );
639 addch( box_area.Pos.L + box_area.Sze.H - 1, box_area.Pos.C, ACS_LLCORNER );
640 addch( box_area.Pos.L, box_area.Pos.C + box_area.Sze.W - 1, ACS_URCORNER );
641 addch( box_area.Pos.L + box_area.Sze.H - 1, box_area.Pos.C + box_area.Sze.W - 1, ACS_LRCORNER );
642 addch( box_area.Pos.L, box_area.Pos.C, ACS_ULCORNER );
651 int NCursesWindow::mvsubwin(
NCursesWindow * sub,
int begin_y,
int begin_x )
655 if ( sub && sub->
parent() )
658 ret = ::mvderwin( sub->
w, begin_y, begin_x );
662 ret = mvsubwin( ch, ch->w->_pary, ch->w->_parx );
671 int NCursesWindow::resize(
int lines,
int columns )
679 return ::wresize( w, lines, columns );
683 std::ostream & operator<<( std::ostream & Stream,
const NCursesWindow * Obj_Cv )
686 return Stream << *Obj_Cv;
688 return Stream <<
"(NoNCWin)";
692 std::ostream & operator<<( std::ostream & Stream,
const NCursesWindow & Obj_Cv )
694 return Stream <<
"NCWin(" << Obj_Cv.
w
int printw(const char *fmt,...)
int vline(int len, chtype ch=0)
bool isDescendant(NCursesWindow &win)
static int NumberOfColors()
int hline(int len, chtype ch=0)
int addwstr(const wchar_t *str, int n=-1)
void err_handler(const char *) const THROWS(NCursesException)
int add_attr_char(int y, int x)
int in_wchar(cchar_t *cchar)
NCursesWindow * sibling()
static void useColors(void)
static int ripoffline(int ripoff_lines, int(*init)(NCursesWindow &win))
int add_wch(const cchar_t *cch)