libyui-ncurses  2.44.1
 All Classes Functions Variables
NCRadioButton.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: NCRadioButton.cc
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCurses.h"
28 #include "NCRadioButton.h"
29 #include "NCRadioButtonGroup.h"
30 
31 
32 NCRadioButton::NCRadioButton( YWidget * parent,
33  const std::string & nlabel,
34  bool check )
35  : YRadioButton( parent, nlabel )
36  , NCWidget( parent )
37  , checked( false )
38 {
39  yuiDebug() << std::endl;
40  setLabel( nlabel );
41  hotlabel = &label;
42  setValue( check );
43 }
44 
45 
46 NCRadioButton::~NCRadioButton()
47 {
48  yuiDebug() << std::endl;
49 }
50 
51 
52 int NCRadioButton::preferredWidth()
53 {
54  return wGetDefsze().W;
55 }
56 
57 
58 int NCRadioButton::preferredHeight()
59 {
60  return wGetDefsze().H;
61 }
62 
63 
64 void NCRadioButton::setEnabled( bool do_bv )
65 {
66  NCWidget::setEnabled( do_bv );
67  YRadioButton::setEnabled( do_bv );
68 }
69 
70 
71 void NCRadioButton::setSize( int newwidth, int newheight )
72 {
73  wRelocate( wpos( 0 ), wsze( newheight, newwidth ) );
74 }
75 
76 
77 void NCRadioButton::setLabel( const std::string & nlabel )
78 {
79  label = NCstring( nlabel );
80  label.stripHotkey();
81  defsze = wsze( label.height(), label.width() + 4 );
82  YRadioButton::setLabel( nlabel );
83  Redraw();
84 }
85 
86 
87 void NCRadioButton::setValue( bool newval )
88 {
89  if ( newval != checked )
90  {
91  checked = newval;
92 
93  if ( checked && buttonGroup() )
94  {
95  buttonGroup()->uncheckOtherButtons( this );
96  }
97 
98  Redraw();
99  }
100 }
101 
102 
103 void NCRadioButton::wRedraw()
104 {
105  if ( !win )
106  return;
107 
108  const NCstyle::StWidget & style( widgetStyle() );
109 
110  win->bkgdset( style.plain );
111 
112  win->printw( 0, 0, "( ) " );
113 
114  label.drawAt( *win, style, wpos( 0, 4 ) );
115 
116  win->bkgdset( style.data );
117 
118  win->printw( 0, 1, "%c", ( checked ? 'x' : ' ' ) );
119 }
120 
121 
122 NCursesEvent NCRadioButton::wHandleInput( wint_t key )
123 {
124  NCursesEvent ret;
125  bool oldChecked = checked;
126  NCRadioButtonGroup * group;
127 
128  switch ( key )
129  {
130  case KEY_HOTKEY:
131  case KEY_SPACE:
132  case KEY_RETURN:
133  setValue( true );
134 
135  if ( notify() && oldChecked != checked )
136  ret = NCursesEvent::ValueChanged;
137 
138  break;
139 
140  case KEY_UP:
141  group = dynamic_cast<NCRadioButtonGroup *>( buttonGroup() );
142 
143  if ( group )
144  group->focusPrevButton();
145 
146  break;
147 
148  case KEY_DOWN:
149  group = dynamic_cast<NCRadioButtonGroup *>( buttonGroup() );
150 
151  if ( group )
152  group->focusNextButton();
153 
154  break;
155  }
156 
157  return ret;
158 }
159 
int printw(const char *fmt,...)
Definition: ncursesw.cc:75
void bkgdset(chtype ch)
Definition: ncursesw.h:1448
Definition: position.h:109
virtual void setEnabled(bool do_bv)=0
Definition: NCWidget.cc:391
Definition: position.h:154
virtual void setEnabled(bool do_bv)