libyui-ncurses  2.57.2
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, NCTableLine::STATE state )
66 {
67  if ( !yitem )
68  return;
69 
70  sellist->addItem( yitem, state );
71 
72  // Calling sellist->addItem() resets the hotcol because
73  // NCTableStyle's constructor sets hotcol to -1.
74  // Set hotcol 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 }
NCTable::stripHotkeys
void stripHotkeys()
Remove all hotkeys from the pad.
Definition: NCTable.h:256
NCTable
A table with rows and columns.
Definition: NCTable.h:43
NCTable::SetSepWidth
void SetSepWidth(const unsigned sepwidth)
Set the separator width.
Definition: NCTable.h:233
NCTable::getCurrentItemPointer
YItem * getCurrentItemPointer()
Return a pointer to the current item (the item under the cursor) or 0 if there is none,...
Definition: NCTable.cc:380
NCTable::getCurrentItem
virtual int getCurrentItem() const
Get the index of the current item (the item under the cursor) or -1 if there is none,...
Definition: NCTable.cc:365
NCPopup
Definition: NCPopup.h:34
wpos
Screen position pair in the order line, column: (L, C)
Definition: position.h:110
NCTable::SetHotCol
void SetHotCol(int hcol)
Set the hotkey column (?).
Definition: NCTable.h:240
NCTable::SetSepChar
void SetSepChar(const chtype colSepchar)
Set the column separator character.
Definition: NCTable.h:226
NCTable::setBigList
void setBigList(bool big)
Set the "big list" flag.
Definition: NCTable.h:251
NCTable::setCurrentItem
virtual void setCurrentItem(int index)
Set the current item to the specified index.
Definition: NCTable.cc:406
NCTable::addItem
virtual void addItem(YItem *yitem)
Add one item.
Definition: NCTable.h:77
NCursesEvent
Definition: NCurses.h:73
NCTable::setItemByKey
bool setItemByKey(int key)
Select an item by its hotkey.
Definition: NCTable.cc:534