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;
384 assert((
w->_maxx + 1 ) ==
cols );
389 int NCursesWindow::ripoff_init( WINDOW *w,
int cols )
393 RIPOFFINIT init = *prip++;
409 if ( code == OK && init && ripoff_lines )
411 R_INIT[r_init_idx++] = init;
426 if ( p->isDescendant( win ) )
439 p->kill_subwindows();
467 else if ( win ==
this )
495 else if (
count < 0 )
504 int NCursesWindow::colorInitialized = COLORS_NOT_INITIALIZED;
509 if ( colorInitialized == COLORS_NOT_INITIALIZED )
513 if ( ::has_colors() )
516 colorInitialized = COLORS_ARE_REALLY_THERE;
519 colorInitialized = COLORS_MONOCHROME;
522 colorInitialized = COLORS_NEED_INITIALIZATION;
531 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
533 if ( pair_content( PAIR_NUMBER(
w->_attrs ), &fore, &back ) )
543 return getback ? back : fore;
548 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
557 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
558 return PAIR_NUMBER(
w->_attrs );
564 NCursesWindow::setpalette(
short fore,
short back,
short pair )
566 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
567 return init_pair( pair, fore, back );
573 NCursesWindow::setpalette(
short fore,
short back )
575 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
576 return setpalette( fore, back, PAIR_NUMBER(
w->_attrs ) );
584 if ( colorInitialized == COLORS_ARE_REALLY_THERE )
586 if (( pair < 1 ) || ( pair > COLOR_PAIRS ) )
599 return (( ::has_key( KEY_MOUSE ) || ::
has_mouse() )
603 NCursesPad::NCursesPad(
int lines,
int cols ) :
NCursesWindow()
613 if (
w == ( WINDOW* )0 )
626 wrect box_area( dim.intersectRelTo( area() ) );
628 if ( box_area.Sze > 0 )
630 hline( box_area.Pos.L, box_area.Pos.C, box_area.Sze.W );
631 hline( box_area.Pos.L + box_area.Sze.H - 1, box_area.Pos.C, box_area.Sze.W );
632 vline( box_area.Pos.L, box_area.Pos.C, box_area.Sze.H );
633 vline( box_area.Pos.L, box_area.Pos.C + box_area.Sze.W - 1, box_area.Sze.H );
635 addch( box_area.Pos.L + box_area.Sze.H - 1, box_area.Pos.C, ACS_LLCORNER );
636 addch( box_area.Pos.L, box_area.Pos.C + box_area.Sze.W - 1, ACS_URCORNER );
637 addch( box_area.Pos.L + box_area.Sze.H - 1, box_area.Pos.C + box_area.Sze.W - 1, ACS_LRCORNER );
638 addch( box_area.Pos.L, box_area.Pos.C, ACS_ULCORNER );
647 int NCursesWindow::mvsubwin(
NCursesWindow * sub,
int begin_y,
int begin_x )
651 if ( sub && sub->
parent() )
654 ret = ::mvderwin( sub->
w, begin_y, begin_x );
658 ret = mvsubwin( ch, ch->w->_pary, ch->w->_parx );
667 int NCursesWindow::resize(
int lines,
int columns )
675 return ::wresize(
w,
lines, columns );
679 std::ostream & operator<<( std::ostream & Stream,
const NCursesWindow * Obj_Cv )
682 return Stream << *Obj_Cv;
684 return Stream <<
"(NoNCWin)";
688 std::ostream & operator<<( std::ostream & Stream,
const NCursesWindow & Obj_Cv )
690 return Stream <<
"NCWin(" << Obj_Cv.
w
NCursesWindow * parent()
Get my parent.
int add_attr_char(int y, int x)
Put attributed character from given position to the window.
int keypad(bool bf)
If called with bf=TRUE, the application will interpret function keys.
virtual ~NCursesWindow()
Destructor.
int begy() const
Line of top left corner relative to stdscr.
NCursesWindow * par
parent, if subwindow
NCursesWindow()
Only for use by derived classes.
NCursesWindow * sib
next subwindow of parent
int add_wch(const cchar_t *cch)
Put a combined character to the window.
int printw(const char *fmt,...)
Do a formatted print to the window.
int addch(const char ch)
Put attributed character to the window.
int addwstr(const wchar_t *str, int n=-1)
Write the wchar_t str to the window, stop writing if the terminating NUL or the limit n is reached.
bool alloced
TRUE if we own the WINDOW.
void kill_subwindows()
Destroy all subwindows.
WINDOW * w
the curses WINDOW
static long count
count of all active windows
int setcolor(short pair)
Set actually used palette entry.
bool isDescendant(NCursesWindow &win)
Return TRUE if win is a descendant of this.
static int NumberOfColors()
Number of available colors.
int meta(bool bf)
If called with bf=TRUE, keys may generate 8-Bit characters.
int attroff(chtype at)
Switch off the window attributes;.
NCursesWindow Clone()
Make an exact copy of the window.
static int lines()
Number of lines on terminal, not window.
int box()
Draw a box around the window with the given vertical and horizontal drawing characters.
int attrset(chtype at)
Set the window attributes;.
NCursesWindow * child()
Get the first child window.
NCursesWindow * sibling()
Get the next child of my parent.
int leaveok(bool bf)
If bf is TRUE, curses will leave the cursor after an update whereever it is after the update.
static int ripoffline(int ripoff_lines, int(*init)(NCursesWindow &win))
This function is used to generate a window of ripped-of lines.
int vline(int len, chtype ch=0)
Draw a vertical line of len characters with the given character.
bool has_mouse() const
Return TRUE if terminal supports a mouse, FALSE otherwise.
void err_handler(const char *) const THROWS(NCursesException)
Signal an error with the given message text.
short getcolor() const
Actual color pair.
int begx() const
Column of top left corner relative to stdscr.
int hline(int len, chtype ch=0)
Draw a horizontal line of len characters with the given character.
static int cols()
Number of cols on terminal, not window.
int in_wchar(cchar_t *cchar)
Retrieve combined character under the current cursor position.
static void useColors(void)
Call this routine very early if you want to have colors.
NCursesWindow * subwins
head of subwindows std::list
int width() const
Number of columns in this window.
int height() const
Number of lines in this window.