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 ) );
311 if ((
unsigned )curs.C < ( *cline ) )
319 beep = !
delch(
true );
333 if ( InputMaxLength >= 0 && InputMaxLength < (
int )getText().length() )
340 beep = !insert( key );
358 bool NCTextPad::insert( wint_t key )
365 if ( key < 32 || ( key >= 127 && key < 160 ) || UCHAR_MAX < key )
370 assertWidth( ++( *cline ) );
375 wattr_get(
w, &attr, &color, NULL );
381 setcchar( &cchar, wch, attr, color, NULL );
384 #ifdef NCURSES_EXT_COLORS
387 ins_wch( curs.L, curs.C++, &cchar );
394 bool NCTextPad::openLine()
396 assertHeight(
lines.size() + 1 );
397 std::list<unsigned>::iterator newl( cline );
398 newl =
lines.insert( ++newl, 0 );
405 ( *newl ) = ( *cline );
411 move( curs.L + 1, 0 );
414 if ((
unsigned )curs.C < ( *cline ) )
417 ( *newl ) = ( *cline ) - curs.C;
420 move( curs.L, curs.C );
421 copywin( *
this, curs.L, curs.C, curs.L + 1, 0, curs.L + 1, ( *newl ),
false );
452 if ((
unsigned )curs.C < *cline )
459 else if ((
unsigned )curs.L + 1 <
lines.size() )
462 std::list<unsigned>::iterator nextl( cline );
464 ( *cline ) += ( *nextl );
465 lines.erase( nextl );
467 assertWidth(( *cline ) );
468 copywin( *
this, curs.L + 1, 0, curs.L, curs.C, curs.L, ( *cline ),
false );
470 move( curs.L + 1, 0 );
480 void NCTextPad::setText(
const NCtext & ntext )
482 bkgd( MY_TEXT_STYLE );
485 if ( ocurs ) cursorOff();
488 assertSze(
wsze( ntext.Lines(), ntext.Columns() + 1 ) );
494 wattr_get(
w, &attr, &color, NULL );
502 for ( NCtext::const_iterator line = ntext.begin(); line != ntext.end(); ++line )
504 lines.push_back(( *line ).str().length() );
508 for ( std::wstring::const_iterator c = line->str().begin(); c != line->str().end(); c++ )
520 setcchar( &cchar, wch, attr, color, NULL );
523 #ifdef NCURSES_EXT_COLORS
533 lines.push_back( 0U );
535 cline =
lines.begin();
545 std::wstring NCTextPad::getText()
const
554 wchar_t wch[CCHARW_MAX+1];
558 for ( std::list<unsigned>::const_iterator cgetl(
lines.begin() ); cgetl !=
lines.end(); ++cgetl )
560 for (
unsigned c = 0; c < ( *cgetl ); ++c )
563 getcchar( &cchar, wch, &attr, &colorpair, NULL );
567 if ( wch[0] == 8677 )
575 if ( l <
lines.size() )
585 std::ostream & operator<<( std::ostream & STREAM,
const NCTextPad & OBJ )
587 STREAM <<
"at " << OBJ.CurPos() <<
" on " <<
wsze( OBJ.
height(), OBJ.
width() )
588 <<
" lines " << OBJ.lines.size() <<
" (" << *OBJ.cline <<
")";
592 void NCTextPad::setInputMaxLength(
int nr )
596 if ( nr >= 0 && nr < (
int )getText().length() )
598 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