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 );
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() );
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 )
182 if ( drect.Sze >
wsze( 0 ) )
184 padpos = ( padpos / drect.Sze ) * drect.Sze;
192 bool NCTextPad::handleInput( wint_t key )
239 if ( (
unsigned) curs.C < ( *cline ) )
243 else if ( (
unsigned) curs.L + 1 < lines.size() )
259 if ( (
unsigned) curs.L + 1 < lines.size() )
288 if ( (
unsigned) curs.L + 1 < lines.size() )
313 if ( (
unsigned) curs.C < ( *cline ) )
321 beep = !
delch(
true );
335 if ( InputMaxLength >= 0 && InputMaxLength < (
int) getText().length() )
342 beep = !insert( key );
360 bool NCTextPad::insert( wint_t key )
367 if ( key < 32 || ( key >= 127 && key < 160 ) || UCHAR_MAX < key )
372 assertWidth( ++( *cline ) );
377 int ret = wattr_get(
w, &attr, &color, NULL );
385 ret = setcchar( &cchar, wch, attr, color, NULL );
391 #ifdef NCURSES_EXT_COLORS
394 ret =
ins_wch( curs.L, curs.C++, &cchar );
401 bool NCTextPad::openLine()
403 assertHeight( lines.size() + 1 );
404 std::list<unsigned>::iterator newl( cline );
405 newl = lines.insert( ++newl, 0 );
412 ( *newl ) = ( *cline );
418 move( curs.L + 1, 0 );
421 if ( (
unsigned) curs.C < ( *cline ) )
424 ( *newl ) = ( *cline ) - curs.C;
427 move( curs.L, curs.C );
428 copywin( *
this, curs.L, curs.C, curs.L + 1, 0, curs.L + 1, ( *newl ),
false );
459 if ( (
unsigned) curs.C < *cline )
466 else if ( (
unsigned) curs.L + 1 < lines.size() )
469 std::list<unsigned>::iterator nextl( cline );
471 ( *cline ) += ( *nextl );
472 lines.erase( nextl );
474 assertWidth(( *cline ) );
475 copywin( *
this, curs.L + 1, 0, curs.L, curs.C, curs.L, ( *cline ),
false );
477 move( curs.L + 1, 0 );
487 void NCTextPad::setText(
const NCtext & ntext )
489 bkgd( MY_TEXT_STYLE );
497 assertSze(
wsze( ntext.Lines(), ntext.Columns() + 1 ) );
503 wattr_get(
w, &attr, &color, NULL );
511 for ( NCtext::const_iterator line = ntext.begin(); line != ntext.end(); ++line )
513 lines.push_back(( *line ).str().length() );
517 for ( std::wstring::const_iterator c = line->str().begin(); c != line->str().end(); c++ )
529 setcchar( &cchar, wch, attr, color, NULL );
532 #ifdef NCURSES_EXT_COLORS
542 lines.push_back( 0U );
544 cline = lines.begin();
554 std::wstring NCTextPad::getText()
const
563 wchar_t wch[CCHARW_MAX+1];
567 for ( std::list<unsigned>::const_iterator cgetl( lines.begin() ); cgetl != lines.end(); ++cgetl )
569 for (
unsigned c = 0; c < ( *cgetl ); ++c )
572 getcchar( &cchar, wch, &attr, &colorpair, NULL );
576 if ( wch[0] == 8677 )
584 if ( l < lines.size() )
594 std::ostream & operator<<( std::ostream & str,
const NCTextPad & obj )
596 str <<
"at " << obj.CurPos() <<
" on " <<
wsze( obj.
height(), obj.
width() )
597 <<
" lines " << obj.lines.size() <<
" (" << *obj.cline <<
")";
601 void NCTextPad::setInputMaxLength(
int nr )
605 if ( nr >= 0 && nr < (
int) getText().length() )
607 NCstring newtext = getText().substr( 0, nr );