25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCTextPad.h"
36 #define MY_TEXT_STYLE ( parw.widgetStyle( true ).data )
38 NCTextPad::NCTextPad(
int l,
int c,
const NCWidget & p )
41 , cline( lines.begin() )
43 , InputMaxLength( -1 )
45 bkgd( MY_TEXT_STYLE );
50 NCTextPad::~NCTextPad()
56 void NCTextPad::resize(
wsze nsze )
61 || nsze.W !=
width() )
68 NCursesPad::resize( nsze.H, nsze.W );
77 void NCTextPad::assertSze(
wsze minsze )
79 if ( minsze.W >
width()
86 void NCTextPad::assertWidth(
unsigned minw )
88 if ( minw >= (
unsigned )
width() )
94 void NCTextPad::assertHeight(
unsigned minh )
96 if ( minh > (
unsigned )
height() )
102 wpos NCTextPad::CurPos()
const
109 void NCTextPad::cursor(
bool on )
113 if (( curson = on ) )
115 bkgdset( parw.wStyle().cursor );
128 int NCTextPad::setpos()
132 chtype oldbkgd = NCattribute::getColor(
getbkgd() );
133 bkgd( MY_TEXT_STYLE );
135 if ( NCattribute::getColor(
getbkgd() ) != oldbkgd )
138 for (
int l = 0; l <
height(); ++l )
139 for (
int c = 0; c <
width(); ++ c )
144 cursor( parw.GetState() == NC::WSactive );
145 return setpos( CurPos() );
150 int NCTextPad::setpos(
const wpos & newpos )
154 if ((
unsigned )npos.L >=
lines.size() )
156 npos.L =
lines.size() - 1;
160 else if ( npos.L != curs.L )
162 advance( cline, npos.L - curs.L );
165 if ((
unsigned )npos.C > *cline )
172 if ( ocurs ) cursorOff();
176 if ( ocurs ) cursorOn();
180 if ( drect.Sze >
wsze( 0 ) )
182 padpos = ( padpos / drect.Sze ) * drect.Sze;
185 return NCPad::setpos( padpos );
190 bool NCTextPad::handleInput( wint_t key )
237 if ((
unsigned )curs.C < ( *cline ) )
241 else if ((
unsigned )curs.L + 1 <
lines.size() )
257 if ((
unsigned )curs.L + 1 <
lines.size() )
274 setpos(
wpos( curs.L - 3, curs.C ) );
286 if ((
unsigned )curs.L + 1 <
lines.size() )
288 setpos(
wpos( curs.L + 3, curs.C ) );
309 if ((
unsigned )curs.C < ( *cline ) )
317 beep = !
delch(
true );
331 if ( InputMaxLength >= 0 && InputMaxLength < (
int )getText().length() )
338 beep = !insert( key );
356 bool NCTextPad::insert( wint_t key )
363 if ( key < 32 || ( key >= 127 && key < 160 ) || UCHAR_MAX < key )
368 assertWidth( ++( *cline ) );
373 wattr_get(
w, &attr, &color, NULL );
379 setcchar( &cchar, wch, attr, color, NULL );
382 #ifdef NCURSES_EXT_COLORS
385 ins_wch( curs.L, curs.C++, &cchar );
392 bool NCTextPad::openLine()
394 assertHeight(
lines.size() + 1 );
395 std::list<unsigned>::iterator newl( cline );
396 newl =
lines.insert( ++newl, 0 );
403 ( *newl ) = ( *cline );
409 move( curs.L + 1, 0 );
412 if ((
unsigned )curs.C < ( *cline ) )
415 ( *newl ) = ( *cline ) - curs.C;
418 move( curs.L, curs.C );
419 copywin( *
this, curs.L, curs.C, curs.L + 1, 0, curs.L + 1, ( *newl ),
false );
450 if ((
unsigned )curs.C < *cline )
457 else if ((
unsigned )curs.L + 1 <
lines.size() )
460 std::list<unsigned>::iterator nextl( cline );
462 ( *cline ) += ( *nextl );
463 lines.erase( nextl );
465 assertWidth(( *cline ) );
466 copywin( *
this, curs.L + 1, 0, curs.L, curs.C, curs.L, ( *cline ),
false );
468 move( curs.L + 1, 0 );
478 void NCTextPad::setText(
const NCtext & ntext )
480 bkgd( MY_TEXT_STYLE );
483 if ( ocurs ) cursorOff();
486 assertSze(
wsze( ntext.Lines(), ntext.Columns() + 1 ) );
492 wattr_get(
w, &attr, &color, NULL );
500 for ( NCtext::const_iterator line = ntext.begin(); line != ntext.end(); ++line )
502 lines.push_back(( *line ).str().length() );
506 for ( std::wstring::const_iterator c = line->str().begin(); c != line->str().end(); c++ )
518 setcchar( &cchar, wch, attr, color, NULL );
521 #ifdef NCURSES_EXT_COLORS
531 lines.push_back( 0U );
533 cline =
lines.begin();
543 std::wstring NCTextPad::getText()
const
552 wchar_t wch[CCHARW_MAX+1];
556 for ( std::list<unsigned>::const_iterator cgetl(
lines.begin() ); cgetl !=
lines.end(); ++cgetl )
558 for (
unsigned c = 0; c < ( *cgetl ); ++c )
561 getcchar( &cchar, wch, &attr, &colorpair, NULL );
565 if ( wch[0] == 8677 )
573 if ( l <
lines.size() )
583 std::ostream & operator<<( std::ostream & STREAM,
const NCTextPad & OBJ )
585 STREAM <<
"at " << OBJ.CurPos() <<
" on " <<
wsze( OBJ.
height(), OBJ.
width() )
586 <<
" lines " << OBJ.lines.size() <<
" (" << *OBJ.cline <<
")";
590 void NCTextPad::setInputMaxLength(
int nr )
594 if ( nr >= 0 && nr < (
int )getText().length() )
596 NCstring newtext = getText().substr( 0, nr );
int clear()
Clear the window.
static int lines()
Number of lines on terminal, not window.
int bkgd(const chtype ch)
Set the background property and apply it to the window.
void bkgdset(chtype ch)
Set the background property.
int maxx() const
Largest x coord in window.
int delch()
Delete character under the cursor.
int insertln()
Insert an empty line above the current line.
int clrtoeol()
Clear to the end of the line.
int copywin(NCursesWindow &win, int sminrow, int smincol, int dminrow, int dmincol, int dmaxrow, int dmaxcol, bool overlay=TRUE)
Overlay or overwrite the rectangle in win given by dminrow,dmincol, dmaxrow,dmaxcol with the rectangl...
int height() const
Number of lines in this window.
int add_attr_char(int y, int x)
Put attributed character from given position to the window.
int in_wchar(cchar_t *cchar)
Retrieve combined character under the current cursor position.
chtype getbkgd() const
Get current background setting.
int move(int y, int x)
Move cursor the this position.
int deleteln()
Delete the current line.
int maxy() const
Largest y coord in window.
int ins_wch(int y, int x, const cchar_t *cchar)
Move cursor to requested position and then insert the attributed character before that position...
int width() const
Number of columns in this window.
WINDOW * w
the curses WINDOW