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: NCMenuButton.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 "NCMenuButton.h" 00029 #include "NCPopupMenu.h" 00030 00031 00032 NCMenuButton::NCMenuButton( YWidget * parent, 00033 std::string nlabel ) 00034 : YMenuButton( parent, nlabel ) 00035 , NCWidget( parent ) 00036 { 00037 yuiDebug() << std::endl; 00038 setLabel( nlabel ); 00039 hotlabel = &label; 00040 } 00041 00042 00043 NCMenuButton::~NCMenuButton() 00044 { 00045 yuiDebug() << std::endl; 00046 } 00047 00048 00049 int NCMenuButton::preferredWidth() 00050 { 00051 return wGetDefsze().W; 00052 } 00053 00054 00055 int NCMenuButton::preferredHeight() 00056 { 00057 return wGetDefsze().H; 00058 } 00059 00060 00061 void NCMenuButton::setEnabled( bool do_bv ) 00062 { 00063 NCWidget::setEnabled( do_bv ); 00064 YMenuButton::setEnabled( do_bv ); 00065 } 00066 00067 00068 void NCMenuButton::setSize( int newwidth, int newheight ) 00069 { 00070 wRelocate( wpos( 0 ), wsze( newheight, newwidth ) ); 00071 } 00072 00073 00074 NCursesEvent NCMenuButton::wHandleInput( wint_t key ) 00075 { 00076 NCursesEvent ret; 00077 00078 switch ( key ) 00079 { 00080 case KEY_HOTKEY: 00081 case KEY_SPACE: 00082 case KEY_RETURN: 00083 case KEY_DOWN: 00084 ret = postMenu(); 00085 break; 00086 } 00087 00088 return ret; 00089 } 00090 00091 00092 void NCMenuButton::setLabel( const std::string & nlabel ) 00093 { 00094 label = NCstring( nlabel ); 00095 label.stripHotkey(); 00096 defsze = wsze( label.height(), label.width() + 3 ); 00097 YMenuButton::setLabel( nlabel ); 00098 Redraw(); 00099 } 00100 00101 00102 void NCMenuButton::wRedraw() 00103 { 00104 if ( !win ) 00105 return; 00106 00107 const NCstyle::StWidget & style( widgetStyle() ); 00108 00109 win->bkgdset( style.plain ); 00110 00111 if ( label.height() > 1 ) 00112 { 00113 win->box( wrect( 0, win->size() - wsze( 0, 1 ) ) ); 00114 } 00115 00116 win->printw( 0, 0, "[" ); 00117 00118 win->printw( 0, win->maxx(), "]" ); 00119 00120 label.drawAt( *win, style, wpos( 0, 1 ), wsze( -1, win->width() - 3 ), 00121 NC::CENTER ); 00122 00123 win->bkgdset( style.scrl ); 00124 win->vline( 0, win->maxx() - 1, win->height(), ' ' ); 00125 haveUtf8() ? 00126 win->add_wch( 0, win->maxx() - 1, WACS_DARROW ) 00127 : win->addch( 0, win->maxx() - 1, ACS_DARROW ); 00128 } 00129 00130 00131 void NCMenuButton::rebuildMenuTree() 00132 { 00133 // NOP 00134 } 00135 00136 00137 NCursesEvent NCMenuButton::postMenu() 00138 { 00139 wpos at( ScreenPos() + wpos( win->height(), 0 ) ); 00140 NCPopupMenu * dialog = new NCPopupMenu( at, 00141 itemsBegin(), 00142 itemsEnd() ); 00143 YUI_CHECK_NEW( dialog ); 00144 00145 int selection = dialog->post(); 00146 00147 if ( selection < 0 ) 00148 { 00149 YDialog::deleteTopmostDialog(); 00150 return NCursesEvent::none; 00151 } 00152 00153 NCursesEvent ret = NCursesEvent::menu; 00154 ret.selection = findMenuItem( selection ); 00155 YDialog::deleteTopmostDialog(); 00156 00157 return ret; 00158 } 00159 00160