libyui-ncurses
2.44.1
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: NCCheckBox.cc 00020 00021 Author: Michael Andres <ma@suse.de> 00022 00023 /-*/ 00024 00025 #define YUILogComponent "ncurses" 00026 #include <yui/YUILog.h> 00027 #include "NCurses.h" 00028 #include "NCCheckBox.h" 00029 00030 00031 unsigned char NCCheckBox::statetag[3] = { '?', ' ', 'x' }; 00032 00033 00034 NCCheckBox::NCCheckBox( YWidget * parent, 00035 const std::string & nlabel, 00036 bool checked ) 00037 : YCheckBox( parent, nlabel ) 00038 , NCWidget( parent ) 00039 , tristate( false ) 00040 , checkstate( checked ? S_ON : S_OFF ) 00041 { 00042 yuiDebug() << std::endl; 00043 setLabel( nlabel ); 00044 hotlabel = &label; 00045 } 00046 00047 00048 NCCheckBox::~NCCheckBox() 00049 { 00050 yuiDebug() << std::endl; 00051 } 00052 00053 00054 int NCCheckBox::preferredWidth() 00055 { 00056 return wGetDefsze().W; 00057 } 00058 00059 00060 int NCCheckBox::preferredHeight() 00061 { 00062 return wGetDefsze().H; 00063 } 00064 00065 00066 void NCCheckBox::setEnabled( bool do_bv ) 00067 { 00068 NCWidget::setEnabled( do_bv ); 00069 YCheckBox::setEnabled( do_bv ); 00070 } 00071 00072 00073 void NCCheckBox::setSize( int newwidth, int newheight ) 00074 { 00075 wRelocate( wpos( 0 ), wsze( newheight, newwidth ) ); 00076 } 00077 00078 00079 void NCCheckBox::setLabel( const std::string & nlabel ) 00080 { 00081 label = NCstring( nlabel ); 00082 label.stripHotkey(); 00083 defsze = wsze( label.height(), label.width() + 4 ); 00084 YCheckBox::setLabel( nlabel ); 00085 Redraw(); 00086 } 00087 00088 00089 void NCCheckBox::setValue( YCheckBoxState state ) 00090 { 00091 switch ( state ) 00092 { 00093 case YCheckBox_on: 00094 checkstate = S_ON; 00095 tristate = false; 00096 break; 00097 00098 case YCheckBox_off: 00099 checkstate = S_OFF; 00100 tristate = false; 00101 break; 00102 00103 case YCheckBox_dont_care: 00104 tristate = true; 00105 checkstate = S_DC; 00106 break; 00107 } 00108 00109 Redraw(); 00110 } 00111 00112 00113 YCheckBoxState NCCheckBox::value() 00114 { 00115 if ( checkstate == S_DC ) 00116 return YCheckBox_dont_care; 00117 00118 if ( checkstate == S_ON ) 00119 return YCheckBox_on; 00120 else 00121 return YCheckBox_off; 00122 } 00123 00124 00125 void NCCheckBox::wRedraw() 00126 { 00127 if ( !win ) 00128 return; 00129 00130 const NCstyle::StWidget & style( widgetStyle() ); 00131 00132 win->bkgdset( style.plain ); 00133 00134 win->printw( 0, 0, "[ ] " ); 00135 00136 label.drawAt( *win, style, wpos( 0, 4 ) ); 00137 00138 win->bkgdset( style.data ); 00139 00140 win->printw( 0, 1, "%c", statetag[checkstate] ); 00141 } 00142 00143 00144 NCursesEvent NCCheckBox::wHandleInput( wint_t key ) 00145 { 00146 NCursesEvent ret; 00147 00148 switch ( key ) 00149 { 00150 case KEY_HOTKEY: 00151 case KEY_SPACE: 00152 case KEY_RETURN: 00153 00154 switch ( checkstate ) 00155 { 00156 case S_DC: 00157 checkstate = S_ON; 00158 break; 00159 00160 case S_ON: 00161 checkstate = S_OFF; 00162 break; 00163 00164 case S_OFF: 00165 checkstate = tristate ? S_DC : S_ON; 00166 break; 00167 } 00168 00169 Redraw(); 00170 00171 if ( notify() ) 00172 ret = NCursesEvent::ValueChanged; 00173 00174 break; 00175 } 00176 00177 return ret; 00178 }