27 #define YUILogComponent "ncurses"
28 #include <yui/YUILog.h>
31 #include <yui/YWidget.h>
34 NCWidget::NCWidget( YWidget * parent )
36 , magic( YWIDGET_MAGIC )
43 , skipNoDimWin( true )
44 , wstate(
NC::WSnormal )
51 ReparentTo( *myparent );
58 NCWidget::NCWidget(
NCWidget * myparent )
60 , magic( YWIDGET_MAGIC )
67 , skipNoDimWin( true )
68 , wstate(
NC::WSnormal )
73 ReparentTo( *myparent );
99 void NCWidget::PreDisconnect()
106 void NCWidget::PostDisconnect()
111 void NCWidget::PreReparent()
116 void NCWidget::PostReparent()
121 bool NCWidget::grabFocus()
123 return Top().Value()->wantFocus( *
this );
129 void NCWidget::wUpdate(
bool forced_br )
134 if ( noUpdates && !forced_br )
143 void NCWidget::Update()
150 Parent()->Value()->Update();
167 return Parent()->Value()->
win;
172 void NCWidget::wMoveChildTo(
NCWidget & child,
const wpos & newpos )
178 child.wMoveTo( newpos );
183 yuiError() << DLOC << child <<
" -> " << newpos <<
" in " <<
this << std::endl;
184 yuiError() << err << std::endl;
194 void NCWidget::wRelocate(
const wrect & newrect )
206 SetState( wstate,
true );
210 yuiError() << *
this << std::endl;
211 yuiError() << err << std::endl;
221 void NCWidget::wMoveTo(
const wpos & newpos )
230 throw NCError(
"wMoveTo: got no parent" );
232 if ( skipNoDimWin && inparent.Sze.H == 0 )
238 if ( skipNoDimWin && inparent.Sze.W == 0 )
244 if ( inparent.Pos != newpos )
248 p.win->mvsubwin(
win,
249 newpos.L + Parent()->Value()->framedim.Pos.L,
250 newpos.C + Parent()->Value()->framedim.Pos.C );
251 inparent.Pos = newpos;
258 void NCWidget::wCreate(
const wrect & newrect )
261 throw NCError(
"wCreate: already have win" );
264 throw NCError(
"wCreate: got no parent" );
268 if ( skipNoDimWin && inparent.Sze ==
wsze( 0, 0 ) )
274 if ( skipNoDimWin && inparent.Sze.H == 0 )
280 if ( skipNoDimWin && inparent.Sze.W == 0 )
288 if ( Parent() && !parw )
290 yuiError() <<
"Can't create widget in nodim parent: " <<
this
291 <<
' ' << inparent <<
" par " << Parent()->Value() << std::endl;
292 inparent.Sze =
wsze( 0, 0 );
303 inparent.Sze.H, inparent.Sze.W,
304 inparent.Pos.L + Parent()->Value()->framedim.Pos.L,
305 inparent.Pos.C + Parent()->Value()->framedim.Pos.C,
313 inparent.Sze.H, inparent.Sze.W,
320 inparent.Sze =
wsze( 1, 1 );
321 inparent.Pos =
wpos( 0, 0 );
329 inparent.Pos.L, inparent.Pos.C );
337 void NCWidget::wDelete()
345 ch->Value()->wDelete();
352 inparent =
wrect( -1, -1 );
359 wpos NCWidget::ScreenPos()
const
366 return Parent()->Value()->ScreenPos() + inparent.Pos;
374 void NCWidget::SetState(
const NC::WState newstate,
bool force )
376 if ( newstate != wstate || force )
383 win->
bkgd( wStyle().getWidget( wstate ).plain );
401 if ( c->HasChildren() )
403 yuiDebug() <<
this <<
"setEnabled children recursively" << std::endl;
405 for ( c = this->
Next();
406 c && c->IsDescendantOf(
this );
409 if ( c->Value()->GetState() != NC::WSdumb )
416 if ( wstate == NC::WSdumb )
419 if ( do_bv && wstate == NC::WSdisabled )
421 SetState( NC::WSnormal );
423 else if ( !do_bv && wstate != NC::WSdisabled )
425 if ( wstate == NC::WSactive )
428 SetState( NC::WSdisabled );
435 void NCWidget::Redraw(
bool sub )
442 bool savNoUpdates = noUpdates;
453 ch->Value()->Redraw( sub );
461 noUpdates = savNoUpdates;
468 void NCWidget::wRedraw()
474 void NCWidget::Recoded()
481 bool savNoUpdates = noUpdates;
488 ch->Value()->Recoded();
491 noUpdates = savNoUpdates;
498 void NCWidget::wRecoded()
505 bool NCWidget::HasHotkey(
int key )
507 if ( key < 0 || UCHAR_MAX < key )
510 if ( !( hotlabel && hotlabel->hasHotkey() ) )
513 return( tolower( key ) == tolower( hotlabel->hotkey() ) );
518 bool NCWidget::HasFunctionHotkey(
int key )
const
520 const YWidget * w =
dynamic_cast<const YWidget *
>( this );
524 if ( key < 0 || ( ! w->hasFunctionKey() ) )
527 return( key == KEY_F( w->functionKey() ) );
531 yuiError() <<
"No YWidget" << std::endl;
540 return wHandleInput( KEY_HOTKEY );
547 return NCursesEvent::none;
551 std::ostream & operator<<( std::ostream & str,
const NCWidget * obj )
553 if ( obj && obj->isValid() )
556 return str <<
"(NoNCWidget)";
560 std::ostream & operator<<( std::ostream & str,
const NCWidget & obj )
563 return str << obj.location() << (
void* )&obj
565 <<
' ' << obj.inparent
569 return str <<
"( invalid NCWidget)";
574 void NCWidget::DumpOn( std::ostream & str, std::string prfx )
const
578 << prfx <<
"+-" <<
this << std::endl;
579 prfx += (
Nsibling() ?
"| " :
" " );
583 ch->Value()->DumpOn( str, prfx );