libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCPushButton.cc
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:       NCPushButton.cc
00020 
00021    Author:     Michael Andres <ma@suse.de>
00022 
00023 /-*/
00024 
00025 #define  YUILogComponent "ncurses"
00026 #include <yui/YUILog.h>
00027 #include <yui/YDialog.h>
00028 #include "NCDialog.h"
00029 #include "NCurses.h"
00030 #include "NCPushButton.h"
00031 
00032 
00033 NCPushButton::NCPushButton( YWidget * parent, const std::string & nlabel )
00034         : YPushButton( parent, nlabel )
00035         , NCWidget( parent )
00036 {
00037     yuiDebug() << std::endl;
00038     setLabel( nlabel );
00039     hotlabel = &label;
00040 }
00041 
00042 
00043 NCPushButton::~NCPushButton()
00044 {
00045     yuiDebug() << std::endl;
00046 }
00047 
00048 
00049 int NCPushButton::preferredWidth()
00050 {
00051     wsze defsize = wGetDefsze();
00052     return wGetDefsze().W;
00053 }
00054 
00055 
00056 int NCPushButton::preferredHeight()
00057 {
00058     return wGetDefsze().H;
00059 }
00060 
00061 
00062 void NCPushButton::setEnabled( bool do_bv )
00063 {
00064     NCWidget::setEnabled( do_bv );
00065     YPushButton::setEnabled( do_bv );
00066 }
00067 
00068 
00069 void NCPushButton::setSize( int newwidth, int newheight )
00070 {
00071     wRelocate( wpos( 0 ), wsze( newheight, newwidth ) );
00072 }
00073 
00074 
00075 NCursesEvent NCPushButton::wHandleInput( wint_t key )
00076 {
00077     NCursesEvent ret;
00078 
00079     switch ( key )
00080     {
00081         case KEY_HOTKEY:
00082         case KEY_RETURN:
00083             ret = NCursesEvent::Activated;
00084             break;
00085     }
00086 
00087     return ret;
00088 }
00089 
00090 
00091 void NCPushButton::setLabel( const std::string & nlabel )
00092 {
00093     label = NCstring( nlabel );
00094     label.stripHotkey();
00095     defsze = wsze( label.height(), label.width() + 2 );
00096     YPushButton::setLabel( nlabel );
00097     Redraw();
00098 }
00099 
00100 
00101 void NCPushButton::wRedraw()
00102 {
00103     if ( !win )
00104         return;
00105 
00106     const NCstyle::StWidget & style( widgetStyle() );
00107 
00108     win->bkgd( style.plain );
00109 
00110     win->clear();
00111 
00112     if ( label.height() <= 1 )
00113     {
00114         win->printw( 0, 0, "[" );
00115         win->printw( 0, win->maxx(), "]" );
00116     }
00117     else
00118     {
00119         win->box();
00120     }
00121 
00122     label.drawAt( *win, style, wpos( 0, 1 ), wsze( -1, win->width() - 2 ),
00123                   NC::CENTER );
00124 }
 All Classes Functions Variables