| 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 | |
| 22 | #ifndef DSELECT_H |
| 23 | #define DSELECT_H |
| 24 | |
| 25 | #include <signal.h> |
| 26 | |
| 27 | #include <algorithm> |
| 28 | |
| 29 | using std::min; |
| 30 | using std::max; |
| 31 | |
| 32 | #include <dpkg/debug.h> |
| 33 | |
| 34 | #include "dselect-curses.h" |
| 35 | |
| 36 | #define DSELECT "dselect" |
| 37 | |
| 38 | #define TOTAL_LIST_WIDTH 180 |
| 39 | #define MAX_DISPLAY_INFO 120 |
| 40 | |
| 41 | struct helpmenuentry { |
| 42 | char key; |
| 43 | const struct helpmessage *msg; |
| 44 | }; |
| 45 | |
| 46 | struct keybindings; |
| 47 | |
| 48 | enum screenparts { |
| 49 | background, |
| 50 | list, |
| 51 | listsel, |
| 52 | title, |
| 53 | thisstate, |
| 54 | selstate, |
| 55 | selstatesel, |
| 56 | colheads, |
| 57 | query, |
| 58 | info_body, |
| 59 | info_head, |
| 60 | whatinfo, |
| 61 | helpscreen, |
| 62 | numscreenparts, |
| 63 | }; |
| 64 | |
| 65 | struct column { |
| 66 | column(): title(nullptr), x(0), width(0) {}; |
| 67 | void blank() { title = nullptr; x = 0; width = 0; }; |
| 68 | |
| 69 | const char *title; |
| 70 | int x; |
| 71 | int width; |
| 72 | }; |
| 73 | |
| 74 | class baselist { |
| 75 | protected: |
| 76 | // Screen dimensions &c. |
| 77 | int xmax, ymax; |
| 78 | int title_height, colheads_height, list_height; |
| 79 | int thisstate_height, info_height, whatinfo_height; |
| 80 | int colheads_row, thisstate_row, info_row, whatinfo_row, list_row; |
| 81 | |
| 82 | int part_attr[numscreenparts]; |
| 83 | |
| 84 | int gap_width; |
| 85 | int col_cur_x; |
| 86 | int total_width; |
| 87 | |
| 88 | void add_column(column &col, const char *title, int width); |
| 89 | void end_column(column &col, const char *title); |
| 90 | void draw_column_head(column &col); |
| 91 | void draw_column_sep(column &col, int y); |
| 92 | void draw_column_item(column &col, int y, const char *item); |
| 93 | |
| 94 | // (n)curses stuff |
| 95 | WINDOW *listpad, *infopad, *colheadspad, *thisstatepad; |
| 96 | WINDOW *titlewin, *whatinfowin, *querywin; |
| 97 | // If listpad is null, then we have not started to display yet, and |
| 98 | // so none of the auto-displaying update routines need to display. |
| 99 | |
| 100 | // SIGWINCH handling |
| 101 | void sigwinch_mask(int how); |
| 102 | void setupsigwinch(); |
| 103 | |
| 104 | static baselist *signallist; |
| 105 | static void sigwinchhandler(int); |
| 106 | |
| 107 | int nitems, ldrawnstart, ldrawnend, showinfo; |
| 108 | int topofscreen, leftofscreen, cursorline; |
| 109 | int infotopofscreen, infolines; |
| 110 | varbuf whatinfovb; |
| 111 | char searchstring[128]; |
| 112 | |
| 113 | virtual void setheights(); |
| 114 | void unsizes(); |
| 115 | void dosearch(); |
| 116 | void displayhelp(const struct helpmenuentry *menu, int key); |
| 117 | void displayerror(const char *str); |
| 118 | |
| 119 | void redrawall(); |
| 120 | void redrawitemsrange(int start /*inclusive*/, int end /*exclusive*/); |
| 121 | void redraw1item(int index); |
| 122 | void refreshlist(); |
| 123 | void refreshinfo(); |
| 124 | void refreshcolheads(); |
| 125 | void setcursor(int index); |
| 126 | |
| 127 | void itd_keys(); |
| 128 | |
| 129 | virtual void redraw1itemsel(int index, int selected) =0; |
| 130 | virtual void redrawcolheads() =0; |
| 131 | virtual void redrawthisstate() =0; |
| 132 | virtual void redrawinfo() =0; |
| 133 | virtual void redrawtitle() =0; |
| 134 | virtual void setwidths() =0; |
| 135 | virtual const char *itemname(int index) =0; |
| 136 | virtual const struct helpmenuentry *helpmenulist() =0; |
| 137 | |
| 138 | virtual bool checksearch(char *str); |
| 139 | virtual bool matchsearch(int index); |
| 140 | void wordwrapinfo(int offset, const char *string); |
| 141 | |
| 142 | public: |
| 143 | |
| 144 | keybindings *bindings; |
| 145 | |
| 146 | void kd_up(); |
| 147 | void kd_down(); |
| 148 | void kd_redraw(); |
| 149 | void kd_scrollon(); |
| 150 | void kd_scrollback(); |
| 151 | void kd_scrollon1(); |
| 152 | void kd_scrollback1(); |
| 153 | void kd_panon(); |
| 154 | void kd_panback(); |
| 155 | void kd_panon1(); |
| 156 | void kd_panback1(); |
| 157 | void kd_top(); |
| 158 | void kd_bottom(); |
| 159 | void kd_iscrollon(); |
| 160 | void kd_iscrollback(); |
| 161 | void kd_iscrollon1(); |
| 162 | void kd_iscrollback1(); |
| 163 | void kd_search(); |
| 164 | void kd_searchagain(); |
| 165 | void kd_help(); |
| 166 | |
| 167 | void startdisplay(); |
| 168 | void enddisplay(); |
| 169 | |
| 170 | baselist(keybindings *); |
| 171 | virtual ~baselist(); |
| 172 | }; |
| 173 | |
| 174 | void displayhelp(const struct helpmenuentry *menu, int key); |
| 175 | |
| 176 | void mywerase(WINDOW *win); |
| 177 | |
| 178 | void curseson(); |
| 179 | void cursesoff(); |
| 180 | |
| 181 | extern bool expertmode; |
| 182 | |
| 183 | struct colordata { |
| 184 | int fore; |
| 185 | int back; |
| 186 | int attr; |
| 187 | }; |
| 188 | extern colordata color[]; |
| 189 | |
| 190 | /* Evil recommends flag variable. */ |
| 191 | extern bool manual_install; |
| 192 | |
| 193 | enum urqresult { urqr_normal, urqr_fail, urqr_quitmenu }; |
| 194 | enum quitaction { qa_noquit, qa_quitchecksave, qa_quitnochecksave }; |
| 195 | |
| 196 | typedef urqresult urqfunction(void); |
| 197 | urqfunction urq_list, urq_quit, urq_menu; |
| 198 | urqfunction urq_setup, urq_update, urq_install, urq_config, urq_remove; |
| 199 | |
| 200 | #endif /* DSELECT_H */ |