2 * dselect - Debian GNU/Linux package maintenance user interface
3 * bcommands.cc - base list keyboard commands display
5 * Copyright (C) 1994,1995 Ian Jackson <iwj10@cus.cam.ac.uk>
7 * This is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
12 * This is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public
18 * License along with this; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 void baselist::kd_scrollon() {
37 topofscreen
+= list_height
;
38 if (topofscreen
> nitems
- list_height
) topofscreen
= nitems
- list_height
;
39 if (topofscreen
< 0) topofscreen
= 0;
40 if (cursorline
< topofscreen
)
41 setcursor(topofscreen
);
45 void baselist::kd_scrollon1() {
46 if (topofscreen
>= nitems
- list_height
) return;
48 if (cursorline
< topofscreen
)
49 setcursor(topofscreen
);
53 void baselist::kd_scrollback() {
54 topofscreen
-= list_height
;
55 if (topofscreen
< 0) topofscreen
= 0;
56 if (cursorline
>= topofscreen
+ list_height
)
57 setcursor(topofscreen
+ list_height
- 1);
61 void baselist::kd_scrollback1() {
62 if (topofscreen
<= 0) return;
64 if (cursorline
>= topofscreen
+ list_height
)
65 setcursor(topofscreen
+ list_height
- 1);
69 void baselist::kd_top() {
70 topofscreen
= 0; setcursor(0);
73 void baselist::kd_bottom() {
74 topofscreen
= nitems
- list_height
;
75 if (topofscreen
< 0) topofscreen
= 0;
76 setcursor(lesserint(topofscreen
+ list_height
- 1, nitems
-1));
79 void baselist::kd_redraw() {
80 //#define RFSH(x) werase(x); redrawwin(x)
84 // RFSH(thisstatepad);
86 // RFSH(whatinfowin); /* fixme-ncurses: why does ncurses need this ? */
89 if (debug
) fprintf(debug
,"baselist[%p]::kd_redraw() done\n",this);
92 void baselist::kd_searchagain() {
93 if (!searchstring
[0]) { beep(); return; }
97 void baselist::kd_search() {
99 mvwaddstr(querywin
,0,0, "Search for ? ");
101 /* fixme: make / RET do `search again' and / DEL to abort */
102 if (wgetnstr(querywin
,searchstring
,sizeof(searchstring
)-1) == ERR
)
105 if (whatinfo_height
) { touchwin(whatinfowin
); refreshinfo(); }
106 else if (info_height
) { touchwin(infopad
); refreshinfo(); }
107 else if (thisstate_height
) redrawthisstate();
108 else { touchwin(listpad
); refreshlist(); }
109 if (searchstring
[0]) dosearch();
112 void baselist::displayhelp(const struct helpmenuentry
*helpmenu
, int key
) {
113 const struct helpmenuentry
*hme
;
114 int maxx
, maxy
, i
, y
, x
, nextkey
;
116 getmaxyx(stdscr
,maxy
,maxx
);
117 clearok(stdscr
,TRUE
);
120 for (hme
= helpmenu
; hme
->key
&& hme
->key
!= key
; hme
++);
123 mvaddstr(1,0, hme
->msg
->text
);
125 mvaddstr(0,0, "Help: ");
126 addstr(hme
->msg
->title
);
128 while (++x
<maxx
) addch(' ');
129 attrset(thisstate_attr
);
131 "? = help menu Space = exit help . = next help or a help page key "
134 while (++x
<maxx
) addch(' ');
139 mvaddstr(1,1, "Help information is available under the following topics:");
140 for (i
=0, hme
=helpmenu
; hme
->key
; hme
++,i
++) {
142 mvaddch(i
+3,3, hme
->key
);
144 mvaddstr(i
+3,6, hme
->msg
->title
);
147 "Press a key from the list above, Space to exit help,\n"
148 " or `.' (full stop) to read each help page in turn. ");
149 nextkey
= helpmenu
[0].key
;
153 if (key
== EOF
) ohshite("error reading keyboard in help");
156 } else if (key
== '?') {
158 } else if (key
== '.') {
163 clearok(stdscr
,TRUE
);
164 wnoutrefresh(stdscr
);
171 wnoutrefresh(whatinfowin
);
174 void baselist::kd_help() {
175 displayhelp(helpmenulist(),0);
178 void baselist::setcursor(int index
) {
179 if (listpad
&& cursorline
!= -1) {
180 redrawitemsrange(cursorline
,cursorline
+1);
181 redraw1itemsel(cursorline
,0);
183 if (cursorline
!= index
) infotopofscreen
= 0;
186 redrawitemsrange(cursorline
,cursorline
+1);
187 redraw1itemsel(cursorline
, showinfo
!= 2);
194 void baselist::kd_down() {
195 int ncursor
= cursorline
;
196 // scroll by one line unless the bottom is already visible
197 // or we're in the top half of the screen ...
198 if (topofscreen
< nitems
- list_height
&&
199 ncursor
>= topofscreen
+ list_height
- 3) topofscreen
++;
200 // move cursor if there are any more ...
201 if (cursorline
+1 < nitems
) ncursor
++;
205 void baselist::kd_up() {
206 int ncursor
= cursorline
;
207 // scroll by one line if there are any lines not shown yet
208 // and we're not in the bottom half the screen ...
209 if (topofscreen
> 0 &&
210 ncursor
<= topofscreen
+ 2) topofscreen
--;
211 // move cursor if there are any to move it to ...
212 if (cursorline
> 0) ncursor
--;
216 void baselist::kd_iscrollon() {
217 infotopofscreen
+= info_height
;
218 if (infotopofscreen
> infolines
- info_height
)
219 infotopofscreen
= infolines
- info_height
;
220 if (infotopofscreen
< 0) infotopofscreen
= 0;
224 void baselist::kd_iscrollback() {
225 infotopofscreen
-= info_height
;
226 if (infotopofscreen
< 0) infotopofscreen
= 0;
230 void baselist::kd_iscrollon1() {
231 if (infotopofscreen
>= infolines
- info_height
) return;
232 infotopofscreen
++; refreshinfo();
235 void baselist::kd_iscrollback1() {
236 if (infotopofscreen
<= 0) return;
237 infotopofscreen
--; refreshinfo();
240 void baselist::kd_panon() {
241 leftofscreen
+= xmax
/3;
242 if (leftofscreen
> total_width
- xmax
) leftofscreen
= total_width
- xmax
;
243 if (leftofscreen
< 0) leftofscreen
= 0;
244 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
247 void baselist::kd_panback() {
248 leftofscreen
-= xmax
/3;
249 if (leftofscreen
< 0) leftofscreen
= 0;
250 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
253 void baselist::kd_panon1() {
255 if (leftofscreen
> total_width
- xmax
) leftofscreen
= total_width
- xmax
;
256 if (leftofscreen
< 0) leftofscreen
= 0;
257 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
260 void baselist::kd_panback1() {
262 if (leftofscreen
< 0) leftofscreen
= 0;
263 refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();