Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  util.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "dialog.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /* Needed in signal handler in mconf.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) int saved_x, saved_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) struct dialog_info dlg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static void set_mono_theme(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	dlg.screen.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	dlg.shadow.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	dlg.dialog.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	dlg.title.atr = A_BOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	dlg.border.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	dlg.button_active.atr = A_REVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	dlg.button_inactive.atr = A_DIM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	dlg.button_key_active.atr = A_REVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	dlg.button_key_inactive.atr = A_BOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	dlg.button_label_active.atr = A_REVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	dlg.button_label_inactive.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	dlg.inputbox.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	dlg.inputbox_border.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	dlg.searchbox.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	dlg.searchbox_title.atr = A_BOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	dlg.searchbox_border.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	dlg.position_indicator.atr = A_BOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	dlg.menubox.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	dlg.menubox_border.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	dlg.item.atr = A_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	dlg.item_selected.atr = A_REVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	dlg.tag.atr = A_BOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	dlg.tag_selected.atr = A_REVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	dlg.tag_key.atr = A_BOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	dlg.tag_key_selected.atr = A_REVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	dlg.check.atr = A_BOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	dlg.check_selected.atr = A_REVERSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	dlg.uarrow.atr = A_BOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	dlg.darrow.atr = A_BOLD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define DLG_COLOR(dialog, f, b, h) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) do {                               \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	dlg.dialog.fg = (f);       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	dlg.dialog.bg = (b);       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	dlg.dialog.hl = (h);       \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static void set_classic_theme(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	DLG_COLOR(screen,                COLOR_CYAN,   COLOR_BLUE,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	DLG_COLOR(shadow,                COLOR_BLACK,  COLOR_BLACK,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	DLG_COLOR(dialog,                COLOR_BLACK,  COLOR_WHITE,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	DLG_COLOR(title,                 COLOR_YELLOW, COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	DLG_COLOR(border,                COLOR_WHITE,  COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	DLG_COLOR(button_active,         COLOR_WHITE,  COLOR_BLUE,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	DLG_COLOR(button_inactive,       COLOR_BLACK,  COLOR_WHITE,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	DLG_COLOR(button_key_active,     COLOR_WHITE,  COLOR_BLUE,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	DLG_COLOR(button_key_inactive,   COLOR_RED,    COLOR_WHITE,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	DLG_COLOR(button_label_active,   COLOR_YELLOW, COLOR_BLUE,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	DLG_COLOR(button_label_inactive, COLOR_BLACK,  COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	DLG_COLOR(inputbox,              COLOR_BLACK,  COLOR_WHITE,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	DLG_COLOR(inputbox_border,       COLOR_BLACK,  COLOR_WHITE,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	DLG_COLOR(searchbox,             COLOR_BLACK,  COLOR_WHITE,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	DLG_COLOR(searchbox_title,       COLOR_YELLOW, COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	DLG_COLOR(searchbox_border,      COLOR_WHITE,  COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	DLG_COLOR(position_indicator,    COLOR_YELLOW, COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	DLG_COLOR(menubox,               COLOR_BLACK,  COLOR_WHITE,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	DLG_COLOR(menubox_border,        COLOR_WHITE,  COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	DLG_COLOR(item,                  COLOR_BLACK,  COLOR_WHITE,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	DLG_COLOR(item_selected,         COLOR_WHITE,  COLOR_BLUE,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	DLG_COLOR(tag,                   COLOR_YELLOW, COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	DLG_COLOR(tag_selected,          COLOR_YELLOW, COLOR_BLUE,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	DLG_COLOR(tag_key,               COLOR_YELLOW, COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	DLG_COLOR(tag_key_selected,      COLOR_YELLOW, COLOR_BLUE,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	DLG_COLOR(check,                 COLOR_BLACK,  COLOR_WHITE,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	DLG_COLOR(check_selected,        COLOR_WHITE,  COLOR_BLUE,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	DLG_COLOR(uarrow,                COLOR_GREEN,  COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	DLG_COLOR(darrow,                COLOR_GREEN,  COLOR_WHITE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static void set_blackbg_theme(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	DLG_COLOR(screen, COLOR_RED,   COLOR_BLACK, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	DLG_COLOR(dialog, COLOR_WHITE, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	DLG_COLOR(title,  COLOR_RED,   COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	DLG_COLOR(border, COLOR_BLACK, COLOR_BLACK, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	DLG_COLOR(button_active,         COLOR_YELLOW, COLOR_RED,   false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	DLG_COLOR(button_inactive,       COLOR_YELLOW, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	DLG_COLOR(button_key_active,     COLOR_YELLOW, COLOR_RED,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	DLG_COLOR(button_key_inactive,   COLOR_RED,    COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	DLG_COLOR(button_label_active,   COLOR_WHITE,  COLOR_RED,   false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	DLG_COLOR(button_label_inactive, COLOR_BLACK,  COLOR_BLACK, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	DLG_COLOR(inputbox,         COLOR_YELLOW, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	DLG_COLOR(inputbox_border,  COLOR_YELLOW, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	DLG_COLOR(searchbox,        COLOR_YELLOW, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	DLG_COLOR(searchbox_title,  COLOR_YELLOW, COLOR_BLACK, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	DLG_COLOR(searchbox_border, COLOR_BLACK,  COLOR_BLACK, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	DLG_COLOR(position_indicator, COLOR_RED, COLOR_BLACK,  false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	DLG_COLOR(menubox,          COLOR_YELLOW, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	DLG_COLOR(menubox_border,   COLOR_BLACK,  COLOR_BLACK, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	DLG_COLOR(item,             COLOR_WHITE, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	DLG_COLOR(item_selected,    COLOR_WHITE, COLOR_RED,   false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	DLG_COLOR(tag,              COLOR_RED,    COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	DLG_COLOR(tag_selected,     COLOR_YELLOW, COLOR_RED,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	DLG_COLOR(tag_key,          COLOR_RED,    COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_RED,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	DLG_COLOR(check,            COLOR_YELLOW, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	DLG_COLOR(check_selected,   COLOR_YELLOW, COLOR_RED,   true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	DLG_COLOR(uarrow, COLOR_RED, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	DLG_COLOR(darrow, COLOR_RED, COLOR_BLACK, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static void set_bluetitle_theme(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	set_classic_theme();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	DLG_COLOR(title,               COLOR_BLUE,   COLOR_WHITE, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	DLG_COLOR(button_key_active,   COLOR_YELLOW, COLOR_BLUE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	DLG_COLOR(button_label_active, COLOR_WHITE,  COLOR_BLUE,  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	DLG_COLOR(searchbox_title,     COLOR_BLUE,   COLOR_WHITE, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	DLG_COLOR(position_indicator,  COLOR_BLUE,   COLOR_WHITE, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	DLG_COLOR(tag,                 COLOR_BLUE,   COLOR_WHITE, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	DLG_COLOR(tag_key,             COLOR_BLUE,   COLOR_WHITE, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * Select color theme
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static int set_theme(const char *theme)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	int use_color = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	if (!theme)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		set_bluetitle_theme();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	else if (strcmp(theme, "classic") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		set_classic_theme();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	else if (strcmp(theme, "bluetitle") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		set_bluetitle_theme();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	else if (strcmp(theme, "blackbg") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		set_blackbg_theme();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	else if (strcmp(theme, "mono") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		use_color = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return use_color;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static void init_one_color(struct dialog_color *color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	static int pair = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	pair++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	init_pair(pair, color->fg, color->bg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	if (color->hl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		color->atr = A_BOLD | COLOR_PAIR(pair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		color->atr = COLOR_PAIR(pair);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) static void init_dialog_colors(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	init_one_color(&dlg.screen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	init_one_color(&dlg.shadow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	init_one_color(&dlg.dialog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	init_one_color(&dlg.title);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	init_one_color(&dlg.border);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	init_one_color(&dlg.button_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	init_one_color(&dlg.button_inactive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	init_one_color(&dlg.button_key_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	init_one_color(&dlg.button_key_inactive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	init_one_color(&dlg.button_label_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	init_one_color(&dlg.button_label_inactive);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	init_one_color(&dlg.inputbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	init_one_color(&dlg.inputbox_border);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	init_one_color(&dlg.searchbox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	init_one_color(&dlg.searchbox_title);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	init_one_color(&dlg.searchbox_border);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	init_one_color(&dlg.position_indicator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	init_one_color(&dlg.menubox);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	init_one_color(&dlg.menubox_border);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	init_one_color(&dlg.item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	init_one_color(&dlg.item_selected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	init_one_color(&dlg.tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	init_one_color(&dlg.tag_selected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	init_one_color(&dlg.tag_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	init_one_color(&dlg.tag_key_selected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	init_one_color(&dlg.check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	init_one_color(&dlg.check_selected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	init_one_color(&dlg.uarrow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	init_one_color(&dlg.darrow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * Setup for color display
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static void color_setup(const char *theme)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	int use_color;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	use_color = set_theme(theme);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (use_color && has_colors()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		start_color();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		init_dialog_colors();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		set_mono_theme();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)  * Set window to attribute 'attr'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) void attr_clear(WINDOW * win, int height, int width, chtype attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	wattrset(win, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	for (i = 0; i < height; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		wmove(win, i, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		for (j = 0; j < width; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			waddch(win, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	touchwin(win);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) void dialog_clear(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int lines, columns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	lines = getmaxy(stdscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	columns = getmaxx(stdscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	attr_clear(stdscr, lines, columns, dlg.screen.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	/* Display background title if it exists ... - SLH */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (dlg.backtitle != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		int i, len = 0, skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		struct subtitle_list *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		wattrset(stdscr, dlg.screen.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		mvwaddstr(stdscr, 0, 1, (char *)dlg.backtitle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		for (pos = dlg.subtitles; pos != NULL; pos = pos->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			/* 3 is for the arrow and spaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			len += strlen(pos->text) + 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		wmove(stdscr, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		if (len > columns - 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			const char *ellipsis = "[...] ";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			waddstr(stdscr, ellipsis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			skip = len - (columns - 2 - strlen(ellipsis));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		for (pos = dlg.subtitles; pos != NULL; pos = pos->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			if (skip == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 				waddch(stdscr, ACS_RARROW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 				skip--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			if (skip == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 				waddch(stdscr, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 				skip--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			if (skip < strlen(pos->text)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 				waddstr(stdscr, pos->text + skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 				skip -= strlen(pos->text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			if (skip == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				waddch(stdscr, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 				skip--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		for (i = len + 1; i < columns - 1; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			waddch(stdscr, ACS_HLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	wnoutrefresh(stdscr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)  * Do some initialization for dialog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int init_dialog(const char *backtitle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	int height, width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	initscr();		/* Init curses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	/* Get current cursor position for signal handler in mconf.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	getyx(stdscr, saved_y, saved_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	getmaxyx(stdscr, height, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (height < WINDOW_HEIGTH_MIN || width < WINDOW_WIDTH_MIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		endwin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		return -ERRDISPLAYTOOSMALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	dlg.backtitle = backtitle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	color_setup(getenv("MENUCONFIG_COLOR"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	keypad(stdscr, TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	cbreak();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	noecho();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	dialog_clear();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) void set_dialog_backtitle(const char *backtitle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	dlg.backtitle = backtitle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) void set_dialog_subtitles(struct subtitle_list *subtitles)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	dlg.subtitles = subtitles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * End using dialog functions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) void end_dialog(int x, int y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	/* move cursor back to original position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	move(y, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	refresh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	endwin();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /* Print the title of the dialog. Center the title and truncate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * tile if wider than dialog (- 2 chars).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) void print_title(WINDOW *dialog, const char *title, int width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	if (title) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		int tlen = MIN(width - 2, strlen(title));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		wattrset(dialog, dlg.title.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		waddch(dialog, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  * Print a string of text in a window, automatically wrap around to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)  * next line if the string is too long to fit on one line. Newline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)  * characters '\n' are propperly processed.  We start on a new line
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)  * if there is no room for at least 4 nonblanks following a double-space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	int newl, cur_x, cur_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	int prompt_len, room, wlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	char tempstr[MAX_LEN + 1], *word, *sp, *sp2, *newline_separator = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	strcpy(tempstr, prompt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	prompt_len = strlen(tempstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	if (prompt_len <= width - x * 2) {	/* If prompt is short */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		wmove(win, y, (width - prompt_len) / 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		waddstr(win, tempstr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		cur_x = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		cur_y = y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		newl = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		word = tempstr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		while (word && *word) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 			sp = strpbrk(word, "\n ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			if (sp && *sp == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 				newline_separator = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 			if (sp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 				*sp++ = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 			/* Wrap to next line if either the word does not fit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 			   or it is the first word of a new sentence, and it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 			   short, and the next word does not fit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 			room = width - cur_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 			wlen = strlen(word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			if (wlen > room ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 			    (newl && wlen < 4 && sp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 			     && wlen + 1 + strlen(sp) > room
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			     && (!(sp2 = strpbrk(sp, "\n "))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 				 || wlen + 1 + (sp2 - sp) > room))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 				cur_y++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 				cur_x = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			wmove(win, cur_y, cur_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 			waddstr(win, word);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 			getyx(win, cur_y, cur_x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			/* Move to the next line if the word separator was a newline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 			if (newline_separator) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 				cur_y++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 				cur_x = x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 				newline_separator = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 				cur_x++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			if (sp && *sp == ' ') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 				cur_x++;	/* double space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 				while (*++sp == ' ') ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 				newl = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 				newl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			word = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)  * Print a button
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) void print_button(WINDOW * win, const char *label, int y, int x, int selected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	int i, temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	wmove(win, y, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	wattrset(win, selected ? dlg.button_active.atr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		 : dlg.button_inactive.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	waddstr(win, "<");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	temp = strspn(label, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	label += temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	wattrset(win, selected ? dlg.button_label_active.atr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		 : dlg.button_label_inactive.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	for (i = 0; i < temp; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		waddch(win, ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	wattrset(win, selected ? dlg.button_key_active.atr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		 : dlg.button_key_inactive.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	waddch(win, label[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	wattrset(win, selected ? dlg.button_label_active.atr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		 : dlg.button_label_inactive.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	waddstr(win, (char *)label + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	wattrset(win, selected ? dlg.button_active.atr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		 : dlg.button_inactive.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	waddstr(win, ">");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	wmove(win, y, x + temp + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  * Draw a rectangular box with line drawing characters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) draw_box(WINDOW * win, int y, int x, int height, int width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	 chtype box, chtype border)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	wattrset(win, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	for (i = 0; i < height; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		wmove(win, y + i, x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		for (j = 0; j < width; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 			if (!i && !j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 				waddch(win, border | ACS_ULCORNER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			else if (i == height - 1 && !j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 				waddch(win, border | ACS_LLCORNER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 			else if (!i && j == width - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 				waddch(win, box | ACS_URCORNER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			else if (i == height - 1 && j == width - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 				waddch(win, box | ACS_LRCORNER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 			else if (!i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 				waddch(win, border | ACS_HLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 			else if (i == height - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 				waddch(win, box | ACS_HLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			else if (!j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 				waddch(win, border | ACS_VLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			else if (j == width - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 				waddch(win, box | ACS_VLINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 				waddch(win, box | ' ');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)  * Draw shadows along the right and bottom edge to give a more 3D look
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)  * to the boxes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) void draw_shadow(WINDOW * win, int y, int x, int height, int width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	if (has_colors()) {	/* Whether terminal supports color? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 		wattrset(win, dlg.shadow.atr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 		wmove(win, y + height, x + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		for (i = 0; i < width; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			waddch(win, winch(win) & A_CHARTEXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 		for (i = y + 1; i < y + height + 1; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 			wmove(win, i, x + width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 			waddch(win, winch(win) & A_CHARTEXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 			waddch(win, winch(win) & A_CHARTEXT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		wnoutrefresh(win);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)  *  Return the position of the first alphabetic character in a string.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) int first_alpha(const char *string, const char *exempt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	int i, in_paren = 0, c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	for (i = 0; i < strlen(string); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		c = tolower(string[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 		if (strchr("<[(", c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 			++in_paren;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		if (strchr(">])", c) && in_paren > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 			--in_paren;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 		if ((!in_paren) && isalpha(c) && strchr(exempt, c) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)  * ncurses uses ESC to detect escaped char sequences. This resutl in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)  * a small timeout before ESC is actually delivered to the application.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)  * lxdialog suggest <ESC> <ESC> which is correctly translated to two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)  * times esc. But then we need to ignore the second esc to avoid stepping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)  * out one menu too much. Filter away all escaped key sequences since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)  * keypad(FALSE) turn off ncurses support for escape sequences - and thats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)  * needed to make notimeout() do as expected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) int on_key_esc(WINDOW *win)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	int key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	int key2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	int key3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	nodelay(win, TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	keypad(win, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	key = wgetch(win);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	key2 = wgetch(win);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		key3 = wgetch(win);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	} while (key3 != ERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	nodelay(win, FALSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	keypad(win, TRUE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	if (key == KEY_ESC && key2 == ERR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		return KEY_ESC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	else if (key != ERR && key != KEY_ESC && key2 == ERR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		ungetch(key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) /* redraw screen in new size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) int on_key_resize(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	dialog_clear();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	return KEY_RESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) struct dialog_list *item_cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) struct dialog_list item_nil;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) struct dialog_list *item_head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) void item_reset(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	struct dialog_list *p, *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	for (p = item_head; p; p = next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		next = p->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 		free(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	item_head = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	item_cur = &item_nil;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) void item_make(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	va_list ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	struct dialog_list *p = malloc(sizeof(*p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	if (item_head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 		item_cur->next = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		item_head = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	item_cur = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 	memset(p, 0, sizeof(*p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	va_start(ap, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	vsnprintf(item_cur->node.str, sizeof(item_cur->node.str), fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	va_end(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) void item_add_str(const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	va_list ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	size_t avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	avail = sizeof(item_cur->node.str) - strlen(item_cur->node.str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	va_start(ap, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	vsnprintf(item_cur->node.str + strlen(item_cur->node.str),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		  avail, fmt, ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	item_cur->node.str[sizeof(item_cur->node.str) - 1] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	va_end(ap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) void item_set_tag(char tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	item_cur->node.tag = tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) void item_set_data(void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	item_cur->node.data = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) void item_set_selected(int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	item_cur->node.selected = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) int item_activate_selected(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	item_foreach()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		if (item_is_selected())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) void *item_data(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	return item_cur->node.data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) char item_tag(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 	return item_cur->node.tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) int item_count(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	struct dialog_list *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	for (p = item_head; p; p = p->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) void item_set(int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	item_foreach()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		if (i++ == n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) int item_n(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	struct dialog_list *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 	for (p = item_head; p; p = p->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		if (p == item_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 			return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 		n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) const char *item_str(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	return item_cur->node.str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) int item_is_selected(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	return (item_cur->node.selected != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) int item_is_tag(char tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	return (item_cur->node.tag == tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) }