libyui-ncurses  2.55.0
NCPushButton.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: NCPushButton.cc
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include <yui/YDialog.h>
28 #include "NCDialog.h"
29 #include "NCurses.h"
30 #include "NCPushButton.h"
31 #include "YNCursesUI.h"
32 
33 
34 NCPushButton::NCPushButton( YWidget * parent, const std::string & nlabel )
35  : YPushButton( parent, nlabel )
36  , NCWidget( parent )
37 {
38  yuiDebug() << std::endl;
39  setLabel( nlabel );
40  hotlabel = &label;
41 }
42 
43 
44 NCPushButton::~NCPushButton()
45 {
46  yuiDebug() << std::endl;
47 }
48 
49 
50 int NCPushButton::preferredWidth()
51 {
52  wsze defsize = wGetDefsze();
53  return wGetDefsze().W;
54 }
55 
56 
57 int NCPushButton::preferredHeight()
58 {
59  return wGetDefsze().H;
60 }
61 
62 
63 void NCPushButton::setEnabled( bool do_bv )
64 {
65  NCWidget::setEnabled( do_bv );
66  YPushButton::setEnabled( do_bv );
67 }
68 
69 
70 void NCPushButton::setSize( int newwidth, int newheight )
71 {
72  wRelocate( wpos( 0 ), wsze( newheight, newwidth ) );
73 }
74 
75 
76 NCursesEvent NCPushButton::wHandleInput( wint_t key )
77 {
78  NCursesEvent ret;
79 
80  switch ( key )
81  {
82  case KEY_HOTKEY:
83  case KEY_RETURN:
84  ret = NCursesEvent::Activated;
85  break;
86  }
87 
88  return ret;
89 }
90 
91 
92 void NCPushButton::setLabel( const std::string & nlabel )
93 {
94  label = NCstring( nlabel );
95  label.stripHotkey();
96  defsze = wsze( label.height(), label.width() + 2 );
97  YPushButton::setLabel( nlabel );
98  Redraw();
99 }
100 
101 
102 void NCPushButton::wRedraw()
103 {
104  if ( !win )
105  return;
106 
107  const NCstyle::StWidget & style( widgetStyle() );
108 
109  win->bkgd( style.plain );
110 
111  win->clear();
112 
113  if ( label.height() <= 1 )
114  {
115  win->printw( 0, 0, "[" );
116  win->printw( 0, win->maxx(), "]" );
117  }
118  else
119  {
120  win->box();
121  }
122 
123  label.drawAt( *win, style, wpos( 0, 1 ), wsze( -1, win->width() - 2 ),
124  NC::CENTER );
125 }
126 
127 // pressing the button
129 {
130  // send an activation event for this widget
131  NCursesEvent event = NCursesEvent::Activated;
132  event.widget = this;
133  YNCursesUI::ui()->sendEvent(event);
134 }
wsze
Definition: position.h:155
NCstring
Definition: NCstring.h:33
YNCursesUI::ui
static YNCursesUI * ui()
Access the global Y2NCursesUI.
Definition: YNCursesUI.h:93
YNCursesUI::sendEvent
void sendEvent(NCursesEvent event)
Send an event to the UI.
Definition: YNCursesUI.cc:455
NCWidget::setEnabled
virtual void setEnabled(bool do_bv)=0
Pure virtual to make sure every widget implements it.
Definition: NCWidget.cc:391
NCPushButton::activate
virtual void activate()
Activate the button.
Definition: NCPushButton.cc:128
NCursesWindow::clear
int clear()
Clear the window.
Definition: ncursesw.h:1521
NCursesWindow::box
int box()
Draw a box around the window with the given vertical and horizontal drawing characters.
Definition: ncursesw.h:1461
NCWidget
Definition: NCWidget.h:46
NCstyle::StWidget
Definition: NCstyle.h:358
NCursesWindow::width
int width() const
Number of columns in this window.
Definition: ncursesw.h:1074
wpos
Definition: position.h:110
NCPushButton::setEnabled
virtual void setEnabled(bool do_bv)
Pure virtual to make sure every widget implements it.
Definition: NCPushButton.cc:63
NCursesWindow::bkgd
int bkgd(const chtype ch)
Set the background property and apply it to the window.
Definition: ncursesw.h:1442
NCursesWindow::printw
int printw(const char *fmt,...)
Do a formatted print to the window.
Definition: ncursesw.cc:75
NCursesEvent
Definition: NCurses.h:73
NCursesWindow::maxx
int maxx() const
Largest x coord in window.
Definition: ncursesw.h:1089