messagebox.c (b319d934379f5b819cd195be7e03dbd407566fd4) | messagebox.c (84823cc70824c8d842f503d8c2e6d7b0c2d95b61) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2021-2022 Alfonso Sabato Siciliano 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 89 unchanged lines hidden (view full) --- 98 pnoutrefresh(textpad, ytextpad, 0, y+1, x+2, y+h-4, x+w-2); 99} 100 101static int 102do_message(struct bsddialog_conf *conf, const char *text, int rows, int cols, 103 struct buttons bs) 104{ 105 bool hastext, loop; | 1/*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2021-2022 Alfonso Sabato Siciliano 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 89 unchanged lines hidden (view full) --- 98 pnoutrefresh(textpad, ytextpad, 0, y+1, x+2, y+h-4, x+w-2); 99} 100 101static int 102do_message(struct bsddialog_conf *conf, const char *text, int rows, int cols, 103 struct buttons bs) 104{ 105 bool hastext, loop; |
106 int y, x, h, w, retval, ytextpad, htextpad, unused; | 106 int y, x, h, w, retval, ytextpad, htextpad, printrows, unused; |
107 WINDOW *widget, *textpad, *shadow; 108 wint_t input; 109 110 if (set_widget_size(conf, rows, cols, &h, &w) != 0) 111 return (BSDDIALOG_ERROR); 112 if (message_autosize(conf, rows, cols, &h, &w, text, &hastext, bs) != 0) 113 return (BSDDIALOG_ERROR); 114 if (message_checksize(h, w, hastext, bs) != 0) 115 return (BSDDIALOG_ERROR); 116 if (set_widget_position(conf, &y, &x, h, w) != 0) 117 return (BSDDIALOG_ERROR); 118 119 if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs, 120 true) != 0) 121 return (BSDDIALOG_ERROR); 122 | 107 WINDOW *widget, *textpad, *shadow; 108 wint_t input; 109 110 if (set_widget_size(conf, rows, cols, &h, &w) != 0) 111 return (BSDDIALOG_ERROR); 112 if (message_autosize(conf, rows, cols, &h, &w, text, &hastext, bs) != 0) 113 return (BSDDIALOG_ERROR); 114 if (message_checksize(h, w, hastext, bs) != 0) 115 return (BSDDIALOG_ERROR); 116 if (set_widget_position(conf, &y, &x, h, w) != 0) 117 return (BSDDIALOG_ERROR); 118 119 if (new_dialog(conf, &shadow, &widget, y, x, h, w, &textpad, text, &bs, 120 true) != 0) 121 return (BSDDIALOG_ERROR); 122 |
123 printrows = h - 4; |
|
123 ytextpad = 0; 124 getmaxyx(textpad, htextpad, unused); 125 unused++; /* fix unused error */ | 124 ytextpad = 0; 125 getmaxyx(textpad, htextpad, unused); 126 unused++; /* fix unused error */ |
126 textupdate(widget, textpad, htextpad, ytextpad, hastext); | |
127 loop = true; 128 while (loop) { | 127 loop = true; 128 while (loop) { |
129 textupdate(widget, textpad, htextpad, ytextpad, hastext); |
|
129 doupdate(); 130 if (get_wch(&input) == ERR) 131 continue; 132 switch (input) { 133 case KEY_ENTER: 134 case 10: /* Enter */ 135 retval = bs.value[bs.curr]; 136 loop = false; --- 18 unchanged lines hidden (view full) --- 155 break; 156 case KEY_RIGHT: 157 if (bs.curr < (int)bs.nbuttons - 1) { 158 bs.curr++; 159 draw_buttons(widget, bs, true); 160 wnoutrefresh(widget); 161 } 162 break; | 130 doupdate(); 131 if (get_wch(&input) == ERR) 132 continue; 133 switch (input) { 134 case KEY_ENTER: 135 case 10: /* Enter */ 136 retval = bs.value[bs.curr]; 137 loop = false; --- 18 unchanged lines hidden (view full) --- 156 break; 157 case KEY_RIGHT: 158 if (bs.curr < (int)bs.nbuttons - 1) { 159 bs.curr++; 160 draw_buttons(widget, bs, true); 161 wnoutrefresh(widget); 162 } 163 break; |
164 case KEY_UP: 165 if (ytextpad > 0) 166 ytextpad--; 167 break; 168 case KEY_DOWN: 169 if (ytextpad + printrows < htextpad) 170 ytextpad++; 171 break; 172 case KEY_HOME: 173 ytextpad = 0; 174 break; 175 case KEY_END: 176 ytextpad = htextpad - printrows; 177 ytextpad = ytextpad < 0 ? 0 : ytextpad; 178 break; 179 case KEY_PPAGE: 180 ytextpad -= printrows; 181 ytextpad = ytextpad < 0 ? 0 : ytextpad; 182 break; 183 case KEY_NPAGE: 184 ytextpad += printrows; 185 if (ytextpad + printrows > htextpad) 186 ytextpad = htextpad - printrows; 187 break; |
|
163 case KEY_F(1): 164 if (conf->key.f1_file == NULL && 165 conf->key.f1_message == NULL) 166 break; 167 if (f1help(conf) != 0) 168 return (BSDDIALOG_ERROR); 169 /* No break, screen size can change */ 170 case KEY_RESIZE: --- 10 unchanged lines hidden (view full) --- 181 return (BSDDIALOG_ERROR); 182 if (set_widget_position(conf, &y, &x, h, w) != 0) 183 return (BSDDIALOG_ERROR); 184 185 if (update_dialog(conf, shadow, widget, y, x, h, w, 186 textpad, text, &bs, true) != 0) 187 return (BSDDIALOG_ERROR); 188 | 188 case KEY_F(1): 189 if (conf->key.f1_file == NULL && 190 conf->key.f1_message == NULL) 191 break; 192 if (f1help(conf) != 0) 193 return (BSDDIALOG_ERROR); 194 /* No break, screen size can change */ 195 case KEY_RESIZE: --- 10 unchanged lines hidden (view full) --- 206 return (BSDDIALOG_ERROR); 207 if (set_widget_position(conf, &y, &x, h, w) != 0) 208 return (BSDDIALOG_ERROR); 209 210 if (update_dialog(conf, shadow, widget, y, x, h, w, 211 textpad, text, &bs, true) != 0) 212 return (BSDDIALOG_ERROR); 213 |
214 printrows = h - 4; |
|
189 getmaxyx(textpad, htextpad, unused); 190 ytextpad = 0; 191 textupdate(widget, textpad, htextpad, ytextpad, hastext); 192 193 /* Important to fix grey lines expanding screen */ 194 refresh(); 195 break; | 215 getmaxyx(textpad, htextpad, unused); 216 ytextpad = 0; 217 textupdate(widget, textpad, htextpad, ytextpad, hastext); 218 219 /* Important to fix grey lines expanding screen */ 220 refresh(); 221 break; |
196 case KEY_UP: 197 if (ytextpad == 0) 198 break; 199 ytextpad--; 200 textupdate(widget, textpad, htextpad, ytextpad, hastext); 201 break; 202 case KEY_DOWN: 203 if (ytextpad + h - 4 >= htextpad) 204 break; 205 ytextpad++; 206 textupdate(widget, textpad, htextpad, ytextpad, hastext); 207 break; | |
208 default: 209 if (shortcut_buttons(input, &bs)) { 210 retval = bs.value[bs.curr]; 211 loop = false; 212 } 213 } 214 } 215 --- 27 unchanged lines hidden --- | 222 default: 223 if (shortcut_buttons(input, &bs)) { 224 retval = bs.value[bs.curr]; 225 loop = false; 226 } 227 } 228 } 229 --- 27 unchanged lines hidden --- |