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 );
53 yuiDebug() <<
"CCC " <<
this <<
" parent " << myparent << std::endl;
58 NCWidget::NCWidget(
NCWidget * myparent )
60 , magic( YWIDGET_MAGIC )
67 , skipNoDimWin( true )
68 , wstate(
NC::WSnormal )
73 ReparentTo( *myparent );
76 yuiDebug() <<
"CCC " <<
this <<
" parent " << myparent << std::endl;
83 yuiDebug() <<
"DD+ " <<
this << std::endl;
87 Fchild()->Disconnect();
93 yuiDebug() <<
"DD- " <<
this << std::endl;
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 )
174 yuiDebug() <<
"mc+ " << DLOC << child <<
" -> " << newpos <<
" in " <<
this << std::endl;
178 child.wMoveTo( newpos );
183 yuiError() << DLOC << child <<
" -> " << newpos <<
" in " <<
this << std::endl;
184 yuiError() << err << std::endl;
189 yuiDebug() <<
"mc- " << DLOC << child << std::endl;
194 void NCWidget::wRelocate(
const wrect & newrect )
196 yuiDebug() <<
"rl+ " <<
this <<
" -> " << newrect << std::endl;
206 SetState( wstate,
true );
210 yuiError() << *
this << std::endl;
211 yuiError() << err << std::endl;
216 yuiDebug() <<
"rl- " <<
this << std::endl;
221 void NCWidget::wMoveTo(
const wpos & newpos )
225 yuiDebug() <<
"No win to move: " <<
this <<
" -> " << newpos << std::endl;
230 throw NCError(
"wMoveTo: got no parent" );
232 if ( skipNoDimWin && inparent.Sze.H == 0 )
234 yuiDebug() <<
"Skip widget with zero height: " <<
this <<
' ' << inparent <<
" par " << Parent()->Value() << std::endl;
238 if ( skipNoDimWin && inparent.Sze.W == 0 )
240 yuiDebug() <<
"Skip widget with zero width: " <<
this <<
' ' << inparent <<
" par " << Parent()->Value() << std::endl;
244 if ( inparent.Pos != newpos )
246 yuiDebug() <<
"mv+ " <<
this <<
" -> " << newpos <<
" par " << Parent()->Value() << std::endl;
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;
252 yuiDebug() <<
"mv- " <<
this << std::endl;
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 ) )
270 yuiDebug() <<
"Skip nodim widget: " <<
this <<
' ' << inparent <<
" par " << Parent()->Value() << std::endl;
274 if ( skipNoDimWin && inparent.Sze.H == 0 )
276 yuiDebug() <<
"Skip widget with zero height: " <<
this <<
' ' << inparent <<
" par " << Parent()->Value() << std::endl;
280 if ( skipNoDimWin && inparent.Sze.W == 0 )
282 yuiDebug() <<
"Skip widget with zero width: " <<
this <<
' ' << inparent <<
" par " << Parent()->Value() << std::endl;
288 if ( Parent() && !parw )
290 yuiError() <<
"Can't create widget in nodim parent: " <<
this <<
' ' << inparent <<
" par " << Parent()->Value() << std::endl;
291 inparent.Sze =
wsze( 0, 0 );
295 yuiDebug() <<
"cw+ " <<
this <<
' ' << inparent <<
" par " << Parent()->Value() << std::endl;
302 inparent.Sze.H, inparent.Sze.W,
303 inparent.Pos.L + Parent()->Value()->framedim.Pos.L,
304 inparent.Pos.C + Parent()->Value()->framedim.Pos.C,
312 inparent.Sze.H, inparent.Sze.W,
319 inparent.Sze =
wsze( 1, 1 );
320 inparent.Pos =
wpos( 0, 0 );
328 inparent.Pos.L, inparent.Pos.C );
331 yuiDebug() <<
"cw- " <<
this <<
' ' << inparent << std::endl;
336 void NCWidget::wDelete()
340 yuiDebug() <<
"wd+ " <<
this << std::endl;
344 ch->Value()->wDelete();
351 inparent =
wrect( -1, -1 );
352 yuiDebug() <<
"wd- " <<
this << std::endl;
358 wpos NCWidget::ScreenPos()
const 365 return Parent()->Value()->ScreenPos() + inparent.Pos;
373 void NCWidget::SetState(
const NC::WState newstate,
bool force )
375 if ( newstate != wstate || force )
377 yuiDebug() << DLOC << wstate <<
" -> " << newstate << std::endl;
382 win->
bkgd( wStyle().getWidget( wstate ).plain );
393 yuiDebug() << DLOC <<
this <<
' ' << do_bv <<
' ' << wstate << std::endl;
400 if ( c->HasChildren() )
402 yuiMilestone() <<
this <<
"setEnabled children recursively" << std::endl;
404 for ( c = this->Next();
405 c && c->IsDescendantOf(
this );
408 if ( c->Value()->GetState() != NC::WSdumb )
415 if ( wstate == NC::WSdumb )
418 if ( do_bv && wstate == NC::WSdisabeled )
420 SetState( NC::WSnormal );
422 else if ( !do_bv && wstate != NC::WSdisabeled )
424 if ( wstate == NC::WSactive )
427 SetState( NC::WSdisabeled );
434 void NCWidget::Redraw(
bool sub )
441 bool savNoUpdates = noUpdates;
452 ch->Value()->Redraw( sub );
460 noUpdates = savNoUpdates;
467 void NCWidget::wRedraw()
473 void NCWidget::Recoded()
480 bool savNoUpdates = noUpdates;
487 ch->Value()->Recoded();
490 noUpdates = savNoUpdates;
497 void NCWidget::wRecoded()
504 bool NCWidget::HasHotkey(
int key )
506 if ( key < 0 || UCHAR_MAX < key )
509 if ( !( hotlabel && hotlabel->hasHotkey() ) )
512 return( tolower( key ) == tolower( hotlabel->hotkey() ) );
517 bool NCWidget::HasFunctionHotkey(
int key )
const 519 const YWidget * w =
dynamic_cast<const YWidget *
>( this );
523 if ( key < 0 || ( ! w->hasFunctionKey() ) )
526 return( key == KEY_F( w->functionKey() ) );
530 yuiError() <<
"No YWidget" << std::endl;
539 return wHandleInput( KEY_HOTKEY );
546 return NCursesEvent::none;
550 std::ostream & operator<<( std::ostream & str,
const NCWidget * obj )
552 if ( obj && obj->isValid() )
555 return str <<
"(NoNCWidget)";
559 std::ostream & operator<<( std::ostream & str,
const NCWidget & obj )
562 return str << obj.location() << (
void* )&obj
564 <<
' ' << obj.inparent
568 return str <<
"( invalid NCWidget)";
573 void NCWidget::DumpOn( std::ostream & str, std::string prfx )
const 577 << prfx <<
"+-" <<
this << std::endl;
578 prfx += ( Nsibling() ?
"| " :
" " );
582 ch->Value()->DumpOn( str, prfx );
int clear()
Clear the window.
NCursesWindow * parent()
Get my parent.
int bkgd(const chtype ch)
Set the background property and apply it to the window.
int begx() const
Column of top left corner relative to stdscr.
int begy() const
Line of top left corner relative to stdscr.