basecmds.cc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * dselect - Debian GNU/Linux package maintenance user interface
  3. * bcommands.cc - base list keyboard commands display
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <iwj10@cus.cam.ac.uk>
  6. *
  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.
  11. *
  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.
  16. *
  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.
  20. */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <curses.h>
  24. #include <assert.h>
  25. #include <signal.h>
  26. extern "C" {
  27. #include <config.h>
  28. #include <dpkg.h>
  29. #include <dpkg-db.h>
  30. }
  31. #include "dselect.h"
  32. #include "helpmsgs.h"
  33. void baselist::kd_scrollon() {
  34. topofscreen += list_height;
  35. if (topofscreen > nitems - list_height) topofscreen= nitems - list_height;
  36. if (topofscreen < 0) topofscreen= 0;
  37. if (cursorline < topofscreen)
  38. setcursor(topofscreen);
  39. refreshlist();
  40. }
  41. void baselist::kd_scrollon1() {
  42. if (topofscreen >= nitems - list_height) return;
  43. topofscreen++;
  44. if (cursorline < topofscreen)
  45. setcursor(topofscreen);
  46. refreshlist();
  47. }
  48. void baselist::kd_scrollback() {
  49. topofscreen -= list_height;
  50. if (topofscreen < 0) topofscreen= 0;
  51. if (cursorline >= topofscreen + list_height)
  52. setcursor(topofscreen + list_height - 1);
  53. refreshlist();
  54. }
  55. void baselist::kd_scrollback1() {
  56. if (topofscreen <= 0) return;
  57. topofscreen--;
  58. if (cursorline >= topofscreen + list_height)
  59. setcursor(topofscreen + list_height - 1);
  60. refreshlist();
  61. }
  62. void baselist::kd_top() {
  63. topofscreen= 0; setcursor(0);
  64. }
  65. void baselist::kd_bottom() {
  66. topofscreen= nitems - list_height;
  67. if (topofscreen < 0) topofscreen= 0;
  68. setcursor(lesserint(topofscreen + list_height - 1, nitems-1));
  69. }
  70. void baselist::kd_redraw() {
  71. //#define RFSH(x) werase(x); redrawwin(x)
  72. // RFSH(listpad);
  73. // RFSH(infopad);
  74. // RFSH(colheadspad);
  75. // RFSH(thisstatepad);
  76. // RFSH(titlewin);
  77. // RFSH(whatinfowin); /* fixme-ncurses: why does ncurses need this ? */
  78. clearok(curscr,TRUE);
  79. redrawall();
  80. if (debug) fprintf(debug,"baselist[%p]::kd_redraw() done\n",this);
  81. }
  82. void baselist::kd_searchagain() {
  83. if (!searchstring[0]) { beep(); return; }
  84. dosearch();
  85. }
  86. void baselist::kd_search() {
  87. char newsearchstring[50];
  88. strcpy(newsearchstring,searchstring);
  89. werase(querywin);
  90. mvwaddstr(querywin,0,0, _("Search for ? "));
  91. echo(); /* fixme: ncurses documentation or implementation */
  92. /* fixme: make / RET do `search again' and / DEL to abort */
  93. if (wgetnstr(querywin,newsearchstring,sizeof(newsearchstring)-1) == ERR)
  94. searchstring[0]= 0;
  95. raise(SIGWINCH); /* fixme: ncurses and xterm arrow keys */
  96. noecho(); /* fixme: ncurses */
  97. if (whatinfo_height) { touchwin(whatinfowin); refreshinfo(); }
  98. else if (info_height) { touchwin(infopad); refreshinfo(); }
  99. else if (thisstate_height) redrawthisstate();
  100. else { touchwin(listpad); refreshlist(); }
  101. if (newsearchstring[0]) {
  102. strcpy(searchstring,newsearchstring);
  103. dosearch();
  104. } else
  105. kd_searchagain();
  106. }
  107. void baselist::displayhelp(const struct helpmenuentry *helpmenu, int key) {
  108. const struct helpmenuentry *hme;
  109. int maxx, maxy, i, y, x, nextkey;
  110. getmaxyx(stdscr,maxy,maxx);
  111. clearok(stdscr,TRUE);
  112. for (;;) {
  113. werase(stdscr);
  114. for (hme= helpmenu; hme->key && hme->key != key; hme++);
  115. if (hme->key) {
  116. attrset(list_attr);
  117. mvaddstr(1,0, gettext(hme->msg->text));
  118. attrset(title_attr);
  119. mvaddstr(0,0, _("Help: "));
  120. addstr(gettext(hme->msg->title));
  121. getyx(stdscr,y,x);
  122. while (++x<maxx) addch(' ');
  123. attrset(thisstate_attr);
  124. mvaddstr(maxy-1,0,
  125. _("? = help menu Space = exit help . = next help or a help page key ")
  126. );
  127. getyx(stdscr,y,x);
  128. while (++x<maxx) addch(' ');
  129. move(maxy,maxx);
  130. attrset(A_NORMAL);
  131. nextkey= hme[1].key;
  132. } else {
  133. mvaddstr(1,1, _("Help information is available under the following topics:"));
  134. for (i=0, hme=helpmenu; hme->key; hme++,i++) {
  135. attrset(A_BOLD);
  136. mvaddch(i+3,3, hme->key);
  137. attrset(A_NORMAL);
  138. mvaddstr(i+3,6, gettext(hme->msg->title));
  139. }
  140. mvaddstr(i+4,1,
  141. _("Press a key from the list above, Space to exit help,\n"
  142. " or `.' (full stop) to read each help page in turn. "));
  143. nextkey= helpmenu[0].key;
  144. }
  145. refresh();
  146. key= getch();
  147. if (key == EOF) ohshite(_("error reading keyboard in help"));
  148. if (key == ' ') {
  149. break;
  150. } else if (key == '?') {
  151. key= 0;
  152. } else if (key == '.') {
  153. key= nextkey;
  154. }
  155. }
  156. werase(stdscr);
  157. clearok(stdscr,TRUE);
  158. wnoutrefresh(stdscr);
  159. redrawtitle();
  160. refreshcolheads();
  161. refreshlist();
  162. redrawthisstate();
  163. refreshinfo();
  164. wnoutrefresh(whatinfowin);
  165. }
  166. void baselist::kd_help() {
  167. displayhelp(helpmenulist(),0);
  168. }
  169. void baselist::setcursor(int index) {
  170. if (listpad && cursorline != -1) {
  171. redrawitemsrange(cursorline,cursorline+1);
  172. redraw1itemsel(cursorline,0);
  173. }
  174. if (cursorline != index) infotopofscreen= 0;
  175. cursorline= index;
  176. if (listpad) {
  177. redrawitemsrange(cursorline,cursorline+1);
  178. redraw1itemsel(cursorline,1);
  179. refreshlist();
  180. redrawthisstate();
  181. }
  182. redrawinfo();
  183. }
  184. void baselist::kd_down() {
  185. int ncursor= cursorline;
  186. // scroll by one line unless the bottom is already visible
  187. // or we're in the top half of the screen ...
  188. if (topofscreen < nitems - list_height &&
  189. ncursor >= topofscreen + list_height - 3) topofscreen++;
  190. // move cursor if there are any more ...
  191. if (cursorline+1 < nitems) ncursor++;
  192. setcursor(ncursor);
  193. }
  194. void baselist::kd_up() {
  195. int ncursor= cursorline;
  196. // scroll by one line if there are any lines not shown yet
  197. // and we're not in the bottom half the screen ...
  198. if (topofscreen > 0 &&
  199. ncursor <= topofscreen + 2) topofscreen--;
  200. // move cursor if there are any to move it to ...
  201. if (cursorline > 0) ncursor--;
  202. setcursor(ncursor);
  203. }
  204. void baselist::kd_iscrollon() {
  205. infotopofscreen += info_height;
  206. if (infotopofscreen > infolines - info_height)
  207. infotopofscreen= infolines - info_height;
  208. if (infotopofscreen < 0) infotopofscreen= 0;
  209. refreshinfo();
  210. }
  211. void baselist::kd_iscrollback() {
  212. infotopofscreen -= info_height;
  213. if (infotopofscreen < 0) infotopofscreen= 0;
  214. refreshinfo();
  215. }
  216. void baselist::kd_iscrollon1() {
  217. if (infotopofscreen >= infolines - info_height) return;
  218. infotopofscreen++; refreshinfo();
  219. }
  220. void baselist::kd_iscrollback1() {
  221. if (infotopofscreen <= 0) return;
  222. infotopofscreen--; refreshinfo();
  223. }
  224. void baselist::kd_panon() {
  225. leftofscreen += xmax/3;
  226. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  227. if (leftofscreen < 0) leftofscreen= 0;
  228. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  229. }
  230. void baselist::kd_panback() {
  231. leftofscreen -= xmax/3;
  232. if (leftofscreen < 0) leftofscreen= 0;
  233. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  234. }
  235. void baselist::kd_panon1() {
  236. leftofscreen++;
  237. if (leftofscreen > total_width - xmax) leftofscreen= total_width - xmax;
  238. if (leftofscreen < 0) leftofscreen= 0;
  239. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  240. }
  241. void baselist::kd_panback1() {
  242. leftofscreen--;
  243. if (leftofscreen < 0) leftofscreen= 0;
  244. refreshcolheads(); refreshlist(); redrawthisstate(); refreshinfo();
  245. }