Beispiel #1
0
static void
charset_handler(control *ctrl, void *unused(data), int event)
{
  char *charset = new_cfg.charset;
  switch (event) {
    when EVENT_REFRESH:
      dlg_update_start(ctrl);
      dlg_listbox_clear(ctrl);
      const char *cs;
      for (int i = 0; (cs = charset_menu[i]); i++)
        dlg_listbox_add(ctrl, cs);
      dlg_update_done(ctrl);
      update_charset();
    when EVENT_UNFOCUS:
      dlg_editbox_set(ctrl, charset);
      update_locale();
    when EVENT_VALCHANGE or EVENT_SELCHANGE:
      dlg_editbox_get(ctrl, charset, sizeof cfg.charset);
      if (event == EVENT_SELCHANGE) {
        if (*charset == '(')
          *charset = 0;
        else 
          *strchr(charset, ' ') = 0;
        update_locale();
      }
  }
}
Beispiel #2
0
static void
locale_handler(control *ctrl, void *unused(data), int event)
{
  char *locale = new_cfg.locale;
  switch (event) {
    when EVENT_REFRESH:
      dlg_update_start(ctrl);
      dlg_listbox_clear(ctrl);
      const char *l;
      for (int i = 0; (l = locale_menu[i]); i++)
        dlg_listbox_add(ctrl, l);
      dlg_update_done(ctrl);
      dlg_editbox_set(ctrl, locale);
    when EVENT_UNFOCUS:
      dlg_editbox_set(ctrl, locale);
      update_charset();
    when EVENT_VALCHANGE or EVENT_SELCHANGE:
      dlg_editbox_get(ctrl, locale, sizeof cfg.locale);
      if (event == EVENT_SELCHANGE) {
        if (*locale == '(')
          *locale = 0;
        update_charset();
      }
  }
}
Beispiel #3
0
static void serial_parity_handler(union control *ctrl, void *dlg,
				  void *data, int event)
{
    static const struct {
	const char *name;
	int val;
    } parities[] = {
	{"None", SER_PAR_NONE},
	{"Odd", SER_PAR_ODD},
	{"Even", SER_PAR_EVEN},
	{"Mark", SER_PAR_MARK},
	{"Space", SER_PAR_SPACE},
    };
    int mask = ctrl->listbox.context.i;
    int i, j;
    Conf *conf = (Conf *)data;

    if (event == EVENT_REFRESH) {
	/* Fetching this once at the start of the function ensures we
	 * remember what the right value is supposed to be when
	 * operations below cause reentrant calls to this function. */
	int oldparity = conf_get_int(conf, CONF_serparity);

	dlg_update_start(ctrl, dlg);
	dlg_listbox_clear(ctrl, dlg);
	for (i = 0; i < lenof(parities); i++)  {
	    if (mask & (1 << i))
		dlg_listbox_addwithid(ctrl, dlg, parities[i].name,
				      parities[i].val);
	}
	for (i = j = 0; i < lenof(parities); i++) {
	    if (mask & (1 << i)) {
		if (oldparity == parities[i].val) {
		    dlg_listbox_select(ctrl, dlg, j);
		    break;
		}
		j++;
	    }
	}
	if (i == lenof(parities)) {    /* an unsupported setting was chosen */
	    dlg_listbox_select(ctrl, dlg, 0);
	    oldparity = SER_PAR_NONE;
	}
	dlg_update_done(ctrl, dlg);
	conf_set_int(conf, CONF_serparity, oldparity);    /* restore */
    } else if (event == EVENT_SELCHANGE) {
	int i = dlg_listbox_index(ctrl, dlg);
	if (i < 0)
	    i = SER_PAR_NONE;
	else
	    i = dlg_listbox_getid(ctrl, dlg, i);
	conf_set_int(conf, CONF_serparity, i);
    }
}
Beispiel #4
0
static void serial_flow_handler(union control *ctrl, void *dlg,
				void *data, int event)
{
    static const struct {
	const char *name;
	int val;
    } flows[] = {
	{"None", SER_FLOW_NONE},
	{"XON/XOFF", SER_FLOW_XONXOFF},
	{"RTS/CTS", SER_FLOW_RTSCTS},
	{"DSR/DTR", SER_FLOW_DSRDTR},
    };
    int mask = ctrl->listbox.context.i;
    int i, j;
    Conf *conf = (Conf *)data;

    if (event == EVENT_REFRESH) {
	/* Fetching this once at the start of the function ensures we
	 * remember what the right value is supposed to be when
	 * operations below cause reentrant calls to this function. */
	int oldflow = conf_get_int(conf, CONF_serflow);

	dlg_update_start(ctrl, dlg);
	dlg_listbox_clear(ctrl, dlg);
	for (i = 0; i < lenof(flows); i++)  {
	    if (mask & (1 << i))
		dlg_listbox_addwithid(ctrl, dlg, flows[i].name, flows[i].val);
	}
	for (i = j = 0; i < lenof(flows); i++) {
	    if (mask & (1 << i)) {
		if (oldflow == flows[i].val) {
		    dlg_listbox_select(ctrl, dlg, j);
		    break;
		}
		j++;
	    }
	}
	if (i == lenof(flows)) {       /* an unsupported setting was chosen */
	    dlg_listbox_select(ctrl, dlg, 0);
	    oldflow = SER_FLOW_NONE;
	}
	dlg_update_done(ctrl, dlg);
	conf_set_int(conf, CONF_serflow, oldflow);/* restore */
    } else if (event == EVENT_SELCHANGE) {
	int i = dlg_listbox_index(ctrl, dlg);
	if (i < 0)
	    i = SER_FLOW_NONE;
	else
	    i = dlg_listbox_getid(ctrl, dlg, i);
	conf_set_int(conf, CONF_serflow, i);
    }
}
Beispiel #5
0
static void serial_parity_handler(union control *ctrl, void *dlg,
				  void *data, int event)
{
    static const struct {
	const char *name;
	int val;
    } parities[] = {
	{"None", SER_PAR_NONE},
	{"Odd", SER_PAR_ODD},
	{"Even", SER_PAR_EVEN},
	{"Mark", SER_PAR_MARK},
	{"Space", SER_PAR_SPACE},
    };
    int mask = ctrl->listbox.context.i;
    int i, j;
    Config *cfg = (Config *)data;

    if (event == EVENT_REFRESH) {
	int oldparity = cfg->serparity;/* preserve past reentrant calls */
	dlg_update_start(ctrl, dlg);
	dlg_listbox_clear(ctrl, dlg);
	for (i = 0; i < lenof(parities); i++)  {
	    if (mask & (1 << i))
		dlg_listbox_addwithid(ctrl, dlg, parities[i].name,
				      parities[i].val);
	}
	for (i = j = 0; i < lenof(parities); i++) {
	    if (mask & (1 << i)) {
		if (oldparity == parities[i].val) {
		    dlg_listbox_select(ctrl, dlg, j);
		    break;
		}
		j++;
	    }
	}
	if (i == lenof(parities)) {    /* an unsupported setting was chosen */
	    dlg_listbox_select(ctrl, dlg, 0);
	    oldparity = SER_PAR_NONE;
	}
	dlg_update_done(ctrl, dlg);
	cfg->serparity = oldparity;    /* restore */
    } else if (event == EVENT_SELCHANGE) {
	int i = dlg_listbox_index(ctrl, dlg);
	if (i < 0)
	    i = SER_PAR_NONE;
	else
	    i = dlg_listbox_getid(ctrl, dlg, i);
	cfg->serparity = i;
    }
}
Beispiel #6
0
static void serial_flow_handler(union control *ctrl, void *dlg,
				void *data, int event)
{
    static const struct {
	const char *name;
	int val;
    } flows[] = {
	{"None", SER_FLOW_NONE},
	{"XON/XOFF", SER_FLOW_XONXOFF},
	{"RTS/CTS", SER_FLOW_RTSCTS},
	{"DSR/DTR", SER_FLOW_DSRDTR},
    };
    int mask = ctrl->listbox.context.i;
    int i, j;
    Config *cfg = (Config *)data;

    if (event == EVENT_REFRESH) {
	int oldflow = cfg->serflow;    /* preserve past reentrant calls */
	dlg_update_start(ctrl, dlg);
	dlg_listbox_clear(ctrl, dlg);
	for (i = 0; i < lenof(flows); i++)  {
	    if (mask & (1 << i))
		dlg_listbox_addwithid(ctrl, dlg, flows[i].name, flows[i].val);
	}
	for (i = j = 0; i < lenof(flows); i++) {
	    if (mask & (1 << i)) {
		if (oldflow == flows[i].val) {
		    dlg_listbox_select(ctrl, dlg, j);
		    break;
		}
		j++;
	    }
	}
	if (i == lenof(flows)) {       /* an unsupported setting was chosen */
	    dlg_listbox_select(ctrl, dlg, 0);
	    oldflow = SER_FLOW_NONE;
	}
	dlg_update_done(ctrl, dlg);
	cfg->serflow = oldflow;	       /* restore */
    } else if (event == EVENT_SELCHANGE) {
	int i = dlg_listbox_index(ctrl, dlg);
	if (i < 0)
	    i = SER_FLOW_NONE;
	else
	    i = dlg_listbox_getid(ctrl, dlg, i);
	cfg->serflow = i;
    }
}
Beispiel #7
0
static void
term_handler(control *ctrl, void *unused(data), int event)
{
  switch (event) {
    when EVENT_REFRESH:
      dlg_update_start(ctrl);
      dlg_listbox_clear(ctrl);
      dlg_listbox_add(ctrl, "xterm");
      dlg_listbox_add(ctrl, "xterm-256color");
      dlg_listbox_add(ctrl, "vt100");
      dlg_update_done(ctrl);
      dlg_editbox_set(ctrl, new_cfg.term);
    when EVENT_VALCHANGE or EVENT_SELCHANGE:
      dlg_editbox_get(ctrl, new_cfg.term, sizeof cfg.term);
  }
}
Beispiel #8
0
static void
printerbox_handler(control *ctrl, void *unused(data), int event)
{
  if (event == EVENT_REFRESH) {
    dlg_update_start(ctrl);
    dlg_listbox_clear(ctrl);
    dlg_listbox_add(ctrl, PRINTER_DISABLED_STRING);
    uint num = printer_start_enum();
    for (uint i = 0; i < num; i++)
      dlg_listbox_add(ctrl, printer_get_name(i));
    printer_finish_enum();
    dlg_editbox_set(
      ctrl, *new_cfg.printer ? new_cfg.printer : PRINTER_DISABLED_STRING
    );
    dlg_update_done(ctrl);
  }
  else if (event == EVENT_VALCHANGE || event == EVENT_SELCHANGE) {
    dlg_editbox_get(ctrl, new_cfg.printer, sizeof (cfg.printer));
    if (strcmp(new_cfg.printer, PRINTER_DISABLED_STRING) == 0)
      *new_cfg.printer = '\0';
  }
}