dselect.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * dselect.h - external definitions for this program
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
  6. * Copyright © 2001 Wichert Akkerman <wakkerma@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #ifndef DSELECT_H
  22. #define DSELECT_H
  23. #include <signal.h>
  24. #include <algorithm>
  25. using std::min;
  26. using std::max;
  27. #include <dpkg/debug.h>
  28. #include "dselect-curses.h"
  29. #define DSELECT "dselect"
  30. #define TOTAL_LIST_WIDTH 180
  31. #define MAX_DISPLAY_INFO 120
  32. struct helpmenuentry {
  33. char key;
  34. const struct helpmessage *msg;
  35. };
  36. struct keybindings;
  37. enum screenparts {
  38. background,
  39. list,
  40. listsel,
  41. title,
  42. thisstate,
  43. selstate,
  44. selstatesel,
  45. colheads,
  46. query,
  47. info_body,
  48. info_head,
  49. whatinfo,
  50. helpscreen,
  51. numscreenparts,
  52. };
  53. struct column {
  54. column(): title(nullptr), x(0), width(0) {};
  55. void blank() { title = nullptr; x = 0; width = 0; };
  56. const char *title;
  57. int x;
  58. int width;
  59. };
  60. class baselist {
  61. protected:
  62. // Screen dimensions &c.
  63. int xmax, ymax;
  64. int title_height, colheads_height, list_height;
  65. int thisstate_height, info_height, whatinfo_height;
  66. int colheads_row, thisstate_row, info_row, whatinfo_row, list_row;
  67. int part_attr[numscreenparts];
  68. int gap_width;
  69. int col_cur_x;
  70. int total_width;
  71. void add_column(column &col, const char *title, int width);
  72. void end_column(column &col, const char *title);
  73. void draw_column_head(column &col);
  74. void draw_column_sep(column &col, int y);
  75. void draw_column_item(column &col, int y, const char *item);
  76. // (n)curses stuff
  77. WINDOW *listpad, *infopad, *colheadspad, *thisstatepad;
  78. WINDOW *titlewin, *whatinfowin, *querywin;
  79. // If listpad is null, then we have not started to display yet, and
  80. // so none of the auto-displaying update routines need to display.
  81. // SIGWINCH handling
  82. void sigwinch_mask(int how);
  83. void setupsigwinch();
  84. static baselist *signallist;
  85. static void sigwinchhandler(int);
  86. int nitems, ldrawnstart, ldrawnend, showinfo;
  87. int topofscreen, leftofscreen, cursorline;
  88. int infotopofscreen, infolines;
  89. varbuf whatinfovb;
  90. char searchstring[128];
  91. virtual void setheights();
  92. void unsizes();
  93. void dosearch();
  94. void displayhelp(const struct helpmenuentry *menu, int key);
  95. void displayerror(const char *str);
  96. void redrawall();
  97. void redrawitemsrange(int start /*inclusive*/, int end /*exclusive*/);
  98. void redraw1item(int index);
  99. void refreshlist();
  100. void refreshinfo();
  101. void refreshcolheads();
  102. void setcursor(int index);
  103. void itd_keys();
  104. virtual void redraw1itemsel(int index, int selected) =0;
  105. virtual void redrawcolheads() =0;
  106. virtual void redrawthisstate() =0;
  107. virtual void redrawinfo() =0;
  108. virtual void redrawtitle() =0;
  109. virtual void setwidths() =0;
  110. virtual const char *itemname(int index) =0;
  111. virtual const struct helpmenuentry *helpmenulist() =0;
  112. virtual bool checksearch(char *str);
  113. virtual bool matchsearch(int index);
  114. void wordwrapinfo(int offset, const char *string);
  115. public:
  116. keybindings *bindings;
  117. void kd_up();
  118. void kd_down();
  119. void kd_redraw();
  120. void kd_scrollon();
  121. void kd_scrollback();
  122. void kd_scrollon1();
  123. void kd_scrollback1();
  124. void kd_panon();
  125. void kd_panback();
  126. void kd_panon1();
  127. void kd_panback1();
  128. void kd_top();
  129. void kd_bottom();
  130. void kd_iscrollon();
  131. void kd_iscrollback();
  132. void kd_iscrollon1();
  133. void kd_iscrollback1();
  134. void kd_search();
  135. void kd_searchagain();
  136. void kd_help();
  137. void startdisplay();
  138. void enddisplay();
  139. baselist(keybindings *);
  140. virtual ~baselist();
  141. };
  142. void displayhelp(const struct helpmenuentry *menu, int key);
  143. void mywerase(WINDOW *win);
  144. void curseson();
  145. void cursesoff();
  146. extern bool expertmode;
  147. struct colordata {
  148. int fore;
  149. int back;
  150. int attr;
  151. };
  152. extern colordata color[];
  153. /* Evil recommends flag variable. */
  154. extern bool manual_install;
  155. enum urqresult { urqr_normal, urqr_fail, urqr_quitmenu };
  156. enum quitaction { qa_noquit, qa_quitchecksave, qa_quitnochecksave };
  157. typedef urqresult urqfunction(void);
  158. urqfunction urq_list, urq_quit, urq_menu;
  159. urqfunction urq_setup, urq_update, urq_install, urq_config, urq_remove;
  160. #endif /* DSELECT_H */