28 #define YUILogComponent "ncurses"
29 #include <yui/YUILog.h>
31 #include "NCInputTextBase.h"
36 NCInputTextBase::NCInputTextBase ( YWidget * parent,
41 , passwd ( passwordMode )
44 , maxFldLength ( maxFld )
45 , maxInputLength ( maxInput )
49 , returnOnReturn_b ( false )
51 yuiDebug() << std::endl;
53 if ( maxInputLength &&
54 ( !maxFldLength || maxFldLength > maxInputLength ) )
56 maxFldLength = maxInputLength;
64 NCInputTextBase::~NCInputTextBase()
68 yuiDebug() << std::endl;
73 int NCInputTextBase::preferredWidth()
75 return wGetDefsze().W;
80 int NCInputTextBase::preferredHeight()
82 return wGetDefsze().H;
94 void NCInputTextBase::setSize (
int newwidth,
int newheight )
96 wRelocate (
wpos ( 0 ),
wsze ( newheight, newwidth ) );
101 void NCInputTextBase::setDefsze()
103 unsigned defwidth = maxFldLength ? maxFldLength : 5;
105 if ( _label.width() > defwidth )
106 defwidth = _label.width();
108 defsze =
wsze ( _label.height() + 1, defwidth );
113 void NCInputTextBase::wCreate (
const wrect & newrect )
115 NCWidget::wCreate ( newrect );
120 wrect lrect ( 0, wsze::min ( newrect.Sze,
121 wsze ( _label.height(), newrect.Sze.W ) ) );
123 if ( lrect.Sze.H == newrect.Sze.H )
126 wrect trect ( 0,
wsze ( 1, newrect.Sze.W ) );
128 trect.Pos.L = lrect.Sze.H > 0 ? lrect.Sze.H : 0;
131 lrect.Sze.H, lrect.Sze.W,
132 lrect.Pos.L, lrect.Pos.C,
136 trect.Sze.H, trect.Sze.W,
137 trect.Pos.L, trect.Pos.C,
140 if ( maxFldLength && maxFldLength < (
unsigned ) newrect.Sze.W )
141 trect.Sze.W = maxFldLength;
143 fldlength = trect.Sze.W;
148 void NCInputTextBase::wDelete()
158 void NCInputTextBase::wRedraw()
166 lwin->
bkgd ( style.plain );
170 _label.drawAt ( *lwin, style );
177 bool NCInputTextBase::bufferFull()
const
179 return ( maxInputLength && buffer.length() == maxInputLength );
184 unsigned NCInputTextBase::maxCursor()
const
186 return ( bufferFull() ? buffer.length() - 1 : buffer.length() );
191 void NCInputTextBase::tUpdate()
196 unsigned maxc = maxCursor();
205 if ( maxc < fldlength )
211 if ( curpos <= fldstart )
213 fldstart = curpos ? curpos - 1 : 0;
216 if ( curpos >= fldstart + fldlength - 1 )
218 fldstart = curpos + ( curpos == maxc ? 1 : 2 ) - fldlength;
224 twin->
bkgd ( widgetStyle (
true ).plain );
230 unsigned end = fldlength;
232 const wchar_t * cp = buffer.data() + fldstart;
235 if ( *cp && fldstart )
238 twin->
addch ( ACS_LARROW );
244 if ( fldstart + fldlength <= maxc )
252 for ( ; *cp && i < end; ++i )
268 for ( ; i < end; ++i )
270 twin->
addch ( ACS_CKBOARD );
274 if ( end < fldlength )
277 twin->
addch ( ACS_RARROW );
281 if ( GetState() == NC::WSactive )
283 twin->
move ( 0, curpos - fldstart );
284 twin->
bkgdset ( wStyle().cursor );
286 if ( curpos < buffer.length() )
289 twin->
addch ( ACS_CKBOARD );