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: NCRadioButton.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 "NCRadioButton.h" 00029 #include "NCRadioButtonGroup.h" 00030 00031 00032 NCRadioButton::NCRadioButton( YWidget * parent, 00033 const std::string & nlabel, 00034 bool check ) 00035 : YRadioButton( parent, nlabel ) 00036 , NCWidget( parent ) 00037 , checked( false ) 00038 { 00039 yuiDebug() << std::endl; 00040 setLabel( nlabel ); 00041 hotlabel = &label; 00042 setValue( check ); 00043 } 00044 00045 00046 NCRadioButton::~NCRadioButton() 00047 { 00048 yuiDebug() << std::endl; 00049 } 00050 00051 00052 int NCRadioButton::preferredWidth() 00053 { 00054 return wGetDefsze().W; 00055 } 00056 00057 00058 int NCRadioButton::preferredHeight() 00059 { 00060 return wGetDefsze().H; 00061 } 00062 00063 00064 void NCRadioButton::setEnabled( bool do_bv ) 00065 { 00066 NCWidget::setEnabled( do_bv ); 00067 YRadioButton::setEnabled( do_bv ); 00068 } 00069 00070 00071 void NCRadioButton::setSize( int newwidth, int newheight ) 00072 { 00073 wRelocate( wpos( 0 ), wsze( newheight, newwidth ) ); 00074 } 00075 00076 00077 void NCRadioButton::setLabel( const std::string & nlabel ) 00078 { 00079 label = NCstring( nlabel ); 00080 label.stripHotkey(); 00081 defsze = wsze( label.height(), label.width() + 4 ); 00082 YRadioButton::setLabel( nlabel ); 00083 Redraw(); 00084 } 00085 00086 00087 void NCRadioButton::setValue( bool newval ) 00088 { 00089 if ( newval != checked ) 00090 { 00091 checked = newval; 00092 00093 if ( checked && buttonGroup() ) 00094 { 00095 buttonGroup()->uncheckOtherButtons( this ); 00096 } 00097 00098 Redraw(); 00099 } 00100 } 00101 00102 00103 void NCRadioButton::wRedraw() 00104 { 00105 if ( !win ) 00106 return; 00107 00108 const NCstyle::StWidget & style( widgetStyle() ); 00109 00110 win->bkgdset( style.plain ); 00111 00112 win->printw( 0, 0, "( ) " ); 00113 00114 label.drawAt( *win, style, wpos( 0, 4 ) ); 00115 00116 win->bkgdset( style.data ); 00117 00118 win->printw( 0, 1, "%c", ( checked ? 'x' : ' ' ) ); 00119 } 00120 00121 00122 NCursesEvent NCRadioButton::wHandleInput( wint_t key ) 00123 { 00124 NCursesEvent ret; 00125 bool oldChecked = checked; 00126 NCRadioButtonGroup * group; 00127 00128 switch ( key ) 00129 { 00130 case KEY_HOTKEY: 00131 case KEY_SPACE: 00132 case KEY_RETURN: 00133 setValue( true ); 00134 00135 if ( notify() && oldChecked != checked ) 00136 ret = NCursesEvent::ValueChanged; 00137 00138 break; 00139 00140 case KEY_UP: 00141 group = dynamic_cast<NCRadioButtonGroup *>( buttonGroup() ); 00142 00143 if ( group ) 00144 group->focusPrevButton(); 00145 00146 break; 00147 00148 case KEY_DOWN: 00149 group = dynamic_cast<NCRadioButtonGroup *>( buttonGroup() ); 00150 00151 if ( group ) 00152 group->focusNextButton(); 00153 00154 break; 00155 } 00156 00157 return ret; 00158 } 00159