| 1124 | |
| 1125 | #define KBD_MOUSE_SETUP_WIDGETS_COUNT 7 |
| 1126 | #define KBD_MOUSE_SETUP_DLG_X_OFFSET 2 /* Horizontal offset */ |
| 1127 | #define KBD_MOUSE_SETUP_DLG_Y_OFFSET 2 /* Vertical offset */ |
| 1128 | #define KBD_MOUSE_SETUP_DLG_EMPTY_LINES_COUNT 3 |
| 1129 | #define KBD_MOUSE_SETUP_LAST_LINE_Y 4 |
| 1130 | |
| 1131 | void |
| 1132 | keyboard_mouse_setup_box (void) |
| 1133 | { |
| 1134 | int dlg_width, dlg_height; |
| 1135 | int line_length; |
| 1136 | int cur_line; |
| 1137 | int old_esc_mode_val; |
| 1138 | char *old_esc_mode_timeout_val; |
| 1139 | QuickWidget *widgets, *w, *endw; |
| 1140 | QuickDialog *dlg; |
| 1141 | char old_esc_mode_timeout_str[BUF_TINY]; |
| 1142 | |
| 1143 | old_esc_mode_val = old_esc_mode; |
| 1144 | g_snprintf (old_esc_mode_timeout_str, sizeof (old_esc_mode_timeout_str), |
| 1145 | " %4i", old_esc_mode_timeout); |
| 1146 | |
| 1147 | widgets = g_new0 (QuickWidget, (KBD_MOUSE_SETUP_WIDGETS_COUNT + 1)); |
| 1148 | dlg = g_new0 (QuickDialog, 1); |
| 1149 | |
| 1150 | endw = widgets + KBD_MOUSE_SETUP_WIDGETS_COUNT; |
| 1151 | |
| 1152 | dlg->title = _(" Keayboard / Mouse Setup "); |
| 1153 | dlg_width = strlen (dlg->title); |
| 1154 | dlg_height = 0; |
| 1155 | |
| 1156 | w = endw - 1; |
| 1157 | |
| 1158 | /* First line of widgets */ |
| 1159 | w->widget_type = quick_checkbox; |
| 1160 | w->relative_y = 1; |
| 1161 | w->text = _("Escape key is cancel key"); |
| 1162 | w->result = &old_esc_mode_val; |
| 1163 | w--; |
| 1164 | |
| 1165 | /* Next line of widgets */ |
| 1166 | w->widget_type = quick_label; |
| 1167 | w->relative_y = 2; |
| 1168 | w->text = _("Escape key timeout "); |
| 1169 | w--; |
| 1170 | |
| 1171 | w->widget_type = quick_input; |
| 1172 | w->relative_y = 2; |
| 1173 | w->text = old_esc_mode_timeout_str; |
| 1174 | /* hotkey_pos contains is used to set the length of the input field. */ |
| 1175 | w->hotkey_pos = strlen (widgets[4].text); |
| 1176 | w->str_result = &old_esc_mode_timeout_val; |
| 1177 | w->histname = "escape-key-timeout"; |
| 1178 | w--; |
| 1179 | |
| 1180 | w->widget_type = quick_label; |
| 1181 | w->relative_y = 2; |
| 1182 | w->text = _(" msec"); |
| 1183 | w--; |
| 1184 | |
| 1185 | /* Last line of widgets */ |
| 1186 | w->widget_type = quick_button; |
| 1187 | w->relative_y = KBD_MOUSE_SETUP_LAST_LINE_Y; |
| 1188 | w->text = _("&OK"); |
| 1189 | w->value = B_ENTER; |
| 1190 | w--; |
| 1191 | |
| 1192 | w->widget_type = quick_label; |
| 1193 | w->relative_y = KBD_MOUSE_SETUP_LAST_LINE_Y; |
| 1194 | w->text = " "; /* padding */ |
| 1195 | w--; |
| 1196 | |
| 1197 | w->widget_type = quick_button; |
| 1198 | w->relative_y = KBD_MOUSE_SETUP_LAST_LINE_Y; |
| 1199 | w->text = _("&Cancel"); |
| 1200 | w->value = B_CANCEL; |
| 1201 | w--; |
| 1202 | |
| 1203 | /* Calculate the dialog width and height based on the dimensions |
| 1204 | of the enclosed widgets. */ |
| 1205 | w = endw - 1; |
| 1206 | line_length = 0; |
| 1207 | cur_line = w->relative_y; |
| 1208 | for (; w >= widgets; w--) { |
| 1209 | if (cur_line != w->relative_y) { |
| 1210 | dlg_height++; |
| 1211 | |
| 1212 | if (line_length > dlg_width) |
| 1213 | dlg_width = line_length; |
| 1214 | |
| 1215 | line_length = 0; |
| 1216 | cur_line = w->relative_y; |
| 1217 | } |
| 1218 | |
| 1219 | w->relative_x = line_length; |
| 1220 | |
| 1221 | if (w->widget_type == quick_button) { |
| 1222 | line_length += button_len (w->text, |
| 1223 | (w->value == B_ENTER ? DEFPUSH_BUTTON : NORMAL_BUTTON)); |
| 1224 | } else { |
| 1225 | line_length += strlen (w->text); |
| 1226 | |
| 1227 | if (w->widget_type == quick_checkbox) |
| 1228 | line_length += 4; /* "[x] " */ |
| 1229 | } |
| 1230 | } |
| 1231 | dlg_height++; |
| 1232 | if (line_length > dlg_width) |
| 1233 | dlg_width = line_length; |
| 1234 | else { |
| 1235 | /* Special handling for the last line of widgets - assume |
| 1236 | that they must be centered. */ |
| 1237 | line_length = (dlg_width - line_length) / 2; |
| 1238 | for (w = widgets; w < endw; w++) { |
| 1239 | if (w->relative_y == KBD_MOUSE_SETUP_LAST_LINE_Y) |
| 1240 | w->relative_x += line_length; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | dlg_width += KBD_MOUSE_SETUP_DLG_X_OFFSET * 2; |
| 1245 | dlg_height += KBD_MOUSE_SETUP_DLG_Y_OFFSET * 2 + |
| 1246 | KBD_MOUSE_SETUP_DLG_EMPTY_LINES_COUNT; |
| 1247 | for (w = widgets; w < endw; w++) { |
| 1248 | w->x_divisions = dlg_width; |
| 1249 | w->y_divisions = dlg_height; |
| 1250 | w->relative_x += KBD_MOUSE_SETUP_DLG_X_OFFSET; |
| 1251 | w->relative_y += KBD_MOUSE_SETUP_DLG_Y_OFFSET; |
| 1252 | } |
| 1253 | |
| 1254 | dlg->xlen = dlg_width; |
| 1255 | dlg->ylen = dlg_height; |
| 1256 | dlg->xpos = dlg->ypos = -1; |
| 1257 | dlg->widgets = widgets; |
| 1258 | dlg->i18n = 1; |
| 1259 | |
| 1260 | if (quick_dialog (dlg) != B_CANCEL) { |
| 1261 | old_esc_mode = old_esc_mode_val; |
| 1262 | if (strlen (old_esc_mode_timeout_val) > 4) /* i.e. 9999 */ |
| 1263 | old_esc_mode_timeout_val[4] = '\0'; |
| 1264 | old_esc_mode_timeout = atoi (old_esc_mode_timeout_val); |
| 1265 | g_free (old_esc_mode_timeout_val); |
| 1266 | } |
| 1267 | |
| 1268 | g_free (widgets); |
| 1269 | g_free (dlg); |
| 1270 | } |