basecmds.cc 7.6 KB

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