25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
28 #include "NCIntField.h"
29 #include "NCPopupTextEntry.h"
30 #include "stringutil.h"
33 using stdutil::numstring;
35 const unsigned NCIntField::taglen = 2;
38 NCIntField::NCIntField( YWidget * parent,
39 const std::string & nlabel,
42 : YIntField( parent, nlabel,
43 minV <= maxV ? minV : maxV,
44 maxV >= minV ? maxV : minV )
52 yuiDebug() << std::endl;
53 vlen = numstring( minValue() ).length();
54 unsigned tmpval = numstring( maxValue() ).length();
65 NCIntField::~NCIntField()
69 yuiDebug() << std::endl;
73 int NCIntField::preferredWidth()
75 return wGetDefsze().W;
79 int NCIntField::preferredHeight()
81 return wGetDefsze().H;
88 YIntField::setEnabled( do_bv );
92 void NCIntField::setSize(
int newwidth,
int newheight )
94 wRelocate(
wpos( 0 ),
wsze( newheight, newwidth ) );
98 void NCIntField::setDefsze()
100 unsigned cols = vlen + taglen;
101 defsze =
wsze( label.height() + 1,
102 label.width() < cols ? cols : label.width() );
106 void NCIntField::wCreate(
const wrect & newrect )
108 NCWidget::wCreate( newrect );
113 wrect lrect( 0, wsze::min( newrect.Sze,
114 wsze( label.height(), newrect.Sze.W ) ) );
116 wrect trect( 0,
wsze( 1, newrect.Sze.W ) );
118 if ( lrect.Sze.H == newrect.Sze.H )
121 trect.Pos.L = lrect.Sze.H > 0 ? lrect.Sze.H : 0;
124 lrect.Sze.H, lrect.Sze.W,
125 lrect.Pos.L, lrect.Pos.C,
129 trect.Sze.H, trect.Sze.W,
130 trect.Pos.L, trect.Pos.C,
138 if ( vlen + 2 < (
unsigned )trect.Sze.W && vlen + 2 < label.width() )
140 vstart = label.width() - vlen - 2;
145 void NCIntField::wDelete()
156 void NCIntField::setLabel(
const std::string & nlabel )
161 YIntField::setLabel( nlabel );
166 void NCIntField::setValueInternal(
int newValue )
175 bool NCIntField::Increment(
const bool bigstep )
177 unsigned dist = maxValue() - cvalue;
182 unsigned step = bigstep ? 10 : 1;
185 setValue( cvalue + step );
187 setValue( maxValue() );
193 bool NCIntField::Decrement(
const bool bigstep )
195 unsigned dist = cvalue - minValue();
200 unsigned step = bigstep ? 10 : 1;
203 setValue( cvalue - step );
205 setValue( minValue() );
211 void NCIntField::wRedraw()
219 lwin->
bkgd( style.plain );
223 label.drawAt( *lwin, style );
229 void NCIntField::tUpdate()
236 twin->
bkgd( widgetStyle(
true ).plain );
240 twin->
printw( 0, vstart,
" %*d ", vlen, cvalue );
244 twin->
addch( 0, vstart,
245 ( cvalue != minValue() ? ACS_DARROW :
' ' ) );
247 twin->
addch( 0, vstart + vlen + 1,
248 ( cvalue != maxValue() ? ACS_UARROW :
' ' ) );
269 beep = !Increment(
true );
273 beep = !Decrement(
true );
278 if ( cvalue != maxValue() )
279 setValue( maxValue() );
285 if ( cvalue != minValue() )
286 setValue( minValue() );
320 if ( notify() && ovlue != cvalue )
321 ret = NCursesEvent::ValueChanged;
327 int NCIntField::enterPopup(
wchar_t first )
329 std::wstring wch( &first );
332 wpos at( ScreenPos() +
wpos( win->
maxy() - 1, vstart + 1 ) );
333 std::string label( std::string(
"[" ) + numstring( minValue() )
334 +
"," + numstring( maxValue() ) +
"]" );
336 std::string text( 1, (
char )first );
338 NCInputField::NUMBER );
339 YUI_CHECK_NEW( dialog );
341 while ( dialog->post() != -1 )
343 int nval = atoi( dialog->value().c_str() );
345 if ( nval < minValue() )
347 dialog->setValue( numstring( minValue() ) );
349 else if ( maxValue() < nval )
351 dialog->setValue( numstring( maxValue() ) );
362 YDialog::deleteTopmostDialog();
int printw(const char *fmt,...)
int bkgd(const chtype ch)
virtual void setEnabled(bool do_bv)