libyui-ncurses  2.44.1
 All Classes Functions Variables
NCPopupTable.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: NCPopupTable.cc
20 
21  Author: Michael Andres <ma@suse.de>
22 
23 /-*/
24 
25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
27 #include "NCPopupTable.h"
28 
29 #include "NCTable.h"
30 #include <yui/YMenuButton.h>
31 
32 
33 NCPopupTable::NCPopupTable( const wpos at )
34  : NCPopup( at, false )
35  , sellist( 0 )
36 {
37 }
38 
39 
40 NCPopupTable::~NCPopupTable()
41 {
42 }
43 
44 
45 void NCPopupTable::createList( std::vector<std::string> & row )
46 {
47  if ( sellist )
48  return ;
49 
50  YTableHeader * tableHeader = new YTableHeader();
51 
52  // sellist = new NCTable( this, row.size() );
53  sellist = new NCTable( this, tableHeader );
54 
55  YUI_CHECK_NEW( sellist );
56 
57  sellist->setBigList( true );
58  sellist->SetSepChar( ' ' );
59  sellist->SetSepWidth( 0 );
60  sellist->SetHotCol( 0 );
61  sellist->setNotify( true );
62 }
63 
64 
65 void NCPopupTable::addItem( YItem *yitem )
66 {
67  if ( !yitem )
68  return;
69 
70  sellist->addItem( yitem );
71 
72  // Calling sellist->addItem() resets the hotcol because
73  // NCTableStyle's constructor sets hotcol to -1.
74  // Set hot coll again:
75  sellist->SetHotCol( 0 );
76 }
77 
78 
79 void NCPopupTable::setCurrentItem( int index )
80 {
81  if ( !sellist )
82  return;
83 
84  sellist->setCurrentItem( index );
85 }
86 
87 
88 int NCPopupTable::getCurrentItem() const
89 {
90  if ( !sellist )
91  return -1;
92 
93  return sellist->getCurrentItem();
94 }
95 
96 
97 YItem * NCPopupTable::getCurrentItemPointer( ) const
98 {
99  if ( !sellist )
100  return 0;
101 
102  return sellist->getCurrentItemPointer( );
103 }
104 
105 
106 NCursesEvent NCPopupTable::wHandleHotkey( wint_t key )
107 {
108  if ( key >= 0 && sellist->setItemByKey( key ) )
109  return wHandleInput( KEY_RETURN );
110 
111  return NCursesEvent::none;
112 }
113 
114 
115 bool NCPopupTable::postAgain()
116 {
117  if ( sellist )
118  {
119  postevent.detail = ( postevent == NCursesEvent::button ) ?
120  sellist->getCurrentItem() : NCursesEvent::NODETAIL;
121  }
122 
123  return false;
124 }
125 
126 
127 void NCPopupTable::stripHotkeys()
128 {
129  if ( sellist )
130  {
131  sellist->stripHotkeys();
132  }
133 }
Definition: position.h:109