26 #define YUILogComponent "ncurses"
27 #include <yui/YUILog.h>
29 #include "NCBusyIndicator.h"
34 #define REPAINT_INTERVAL 100
59 struct itimerval interval;
62 void NCBusyIndicatorHandlerWrapper(
int sig_num );
67 NCBusyIndicator::NCBusyIndicator( YWidget * parent,
68 const std::string & nlabel,
70 : YBusyIndicator( parent, nlabel, timeout )
80 yuiDebug() << std::endl;
88 NCBusyIndicatorObject =
this;
89 _timer_divisor = ( double ) REPAINT_INTERVAL / (
double ) timeout;
93 signal( SIGALRM, NCBusyIndicatorHandlerWrapper );
94 interval.it_value.tv_sec = 0;
95 interval.it_value.tv_usec = REPAINT_INTERVAL * 1000;
96 setitimer( ITIMER_REAL, &interval, NULL );
101 NCBusyIndicator::~NCBusyIndicator()
103 NCBusyIndicatorObject = NULL;
106 yuiDebug() << std::endl;
110 int NCBusyIndicator::preferredWidth()
112 return wGetDefsze().W;
116 int NCBusyIndicator::preferredHeight()
118 return wGetDefsze().H;
125 YBusyIndicator::setEnabled( do_bv );
129 void NCBusyIndicator::setSize(
int newwidth,
int newheight )
131 wRelocate(
wpos( 0 ),
wsze( newheight, newwidth ) );
135 void NCBusyIndicator::setDefsze()
137 defsze =
wsze( _label.height() + 1,
138 _label.width() < 5 ? 5 : _label.width() );
142 void NCBusyIndicator::wCreate(
const wrect & newrect )
144 NCWidget::wCreate( newrect );
149 wrect lrect( 0, wsze::min( newrect.Sze,
150 wsze( _label.height(), newrect.Sze.W ) ) );
152 wrect trect( 0,
wsze( 1, newrect.Sze.W ) );
154 if ( lrect.Sze.H == newrect.Sze.H )
157 trect.Pos.L = lrect.Sze.H > 0 ? lrect.Sze.H : 0;
160 lrect.Sze.H, lrect.Sze.W,
161 lrect.Pos.L, lrect.Pos.C,
165 trect.Sze.H, trect.Sze.W,
166 trect.Pos.L, trect.Pos.C,
171 void NCBusyIndicator::wDelete()
181 void NCBusyIndicator::setLabel(
const std::string & nlabel )
185 YBusyIndicator::setLabel( nlabel );
195 _timer_progress += _timer_divisor;
197 if ( _timer_progress >= 1 )
206 interval.it_value.tv_sec = 0;
207 interval.it_value.tv_usec = REPAINT_INTERVAL * 1000;
208 setitimer( ITIMER_REAL, &interval, NULL );
218 void NCBusyIndicatorHandlerWrapper(
int sig_num )
220 signal( SIGALRM, SIG_IGN );
221 NCBusyIndicatorObject->
handler( sig_num );
222 signal( SIGALRM, NCBusyIndicatorHandlerWrapper );
231 void NCBusyIndicator::update()
236 if ( _position > 1.0 || _position < 0 )
237 _rightwards = !_rightwards;
240 _position += STEP_SIZE;
242 _position -= STEP_SIZE;
261 void NCBusyIndicator::setTimeout(
int newTimeout )
263 if ( newTimeout < 1 )
266 _timeout = newTimeout;
267 YBusyIndicator::setTimeout( newTimeout );
268 _timer_divisor = (double) REPAINT_INTERVAL / (
double) _timeout;
281 chtype bg = wStyle().dumb.text;
284 _label.drawAt( *_lwin, bg, bg );
292 void NCBusyIndicator::tUpdate()
297 int cp = ( int )(( _twin->
maxx() ) * _position );
301 _twin->
bkgdset( style.nonbar.chattr );
304 if ( cp <= _twin->maxx() )
306 _twin->
bkgdset( NCattribute::getNonChar( style.bar.chattr ) );
307 _twin->
move( 0, cp );
308 _twin->
addch( NCattribute::getChar( style.bar.chattr ) );
virtual void wRedraw()
draw busy indicator widget
virtual void setEnabled(bool do_bv)
Pure virtual to make sure every widget implements it.
void handler(int sig_num)
handler, called by NCBusyIndicatorHandlerWrapper
virtual void setAlive(bool newAlive)
std::set alive or stalled
int maxx() const
Largest x coord in window.
int move(int y, int x)
Move cursor the this position.
int addch(const char ch)
Put attributed character to the window.
void bkgdset(chtype ch)
Set the background property.
int clear()
Clear the window.