25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
28 #include "NCCheckBoxFrame.h"
31 NCCheckBoxFrame::NCCheckBoxFrame( YWidget * parent,
const std::string & nlabel,
33 : YCheckBoxFrame( parent, nlabel, checked )
36 yuiDebug() << std::endl;
37 wstate = NC::WSnormal;
38 framedim.Pos =
wpos( 1 );
39 framedim.Sze =
wsze( 2 );
41 setLabel( YCheckBoxFrame::label() );
44 if ( invertAutoEnable() )
53 NCCheckBoxFrame::~NCCheckBoxFrame()
55 yuiDebug() << std::endl;
59 int NCCheckBoxFrame::preferredWidth()
61 defsze.W = hasChildren() ? firstChild()->preferredWidth() : 0;
63 if ( label.width() > ( unsigned )defsze.W )
64 defsze.W = label.width();
66 defsze.W += framedim.Sze.W + 4;
72 int NCCheckBoxFrame::preferredHeight()
74 defsze.H = hasChildren() ? firstChild()->preferredHeight() : 0;
75 defsze.H += framedim.Sze.H;
81 void NCCheckBoxFrame::setSize(
int newwidth,
int newheight )
83 wsze csze( newheight, newwidth );
84 wRelocate(
wpos( 0 ), csze );
85 csze = wsze::max( 0, csze - framedim.Sze );
88 firstChild()->setSize( csze.W, csze.H );
92 void NCCheckBoxFrame::setLabel(
const std::string & nlabel )
94 YCheckBoxFrame::setLabel( nlabel );
96 label =
NCstring( YCheckBoxFrame::label() );
102 bool NCCheckBoxFrame::getParentValue(
NCWidget * widget,
bool initial )
104 bool enabled = initial;
107 c && widget->IsDescendantOf( c );
113 enabled = frame->getValue();
115 if ( frame->GetState() == NC::WSdisabeled )
126 YWidget::setEnabled( do_bv );
130 c && c->IsDescendantOf(
this );
133 if ( c->Value()->GetState() != NC::WSdumb )
135 do_it = getParentValue( c->Value(), do_it );
137 c->Value()->setEnabled( do_it );
139 c->Value()->SetState( do_it ? NC::WSnormal : NC::WSdisabeled,
true );
145 bool NCCheckBoxFrame::gotBuddy()
147 if ( !label.hasHotkey() )
151 c && c->IsDescendantOf(
this );
154 if ( c->Value()->GetState() != NC::WSdumb )
162 void NCCheckBoxFrame::wRedraw()
167 chtype bg = wStyle().dumb.text;
172 label.drawAt( *win, widgetStyle(),
wpos( 0, 5 ),
173 wsze( 1, win->
width() - 6 ), NC::TOPLEFT,
false );
175 label.drawAt( *win, bg, bg,
wpos( 0, 5 ),
176 wsze( 1, win->
width() - 6 ), NC::TOPLEFT,
false );
181 win->
printw( 0, 1,
"[ ] " );
183 if ( !invertAutoEnable() )
186 win->
printw( 0, 2,
"%c",
'x' );
188 win->
printw( 0, 2,
"%c",
' ' );
193 win->
printw( 0, 2,
"%c",
' ' );
195 win->
printw( 0, 2,
"%c",
'x' );
203 NCursesEvent NCCheckBoxFrame::wHandleInput( wint_t key )
207 if ( key == KEY_SPACE ||
211 if ( getValue() ==
true )
224 ret = NCursesEvent::ValueChanged;
231 bool NCCheckBoxFrame::setKeyboardFocus()
234 return YWidget::setKeyboardFocus();
240 bool NCCheckBoxFrame::value()