Exemple #1
0
int
area_cursor(struct form_control *fc, struct form_state *fs)
{
	struct line_info *line;
	int x, y;

	assert(fc && fs);
	if_assert_failed return 0;

	line = format_text(fs->value, fc->cols, fc->wrap, 0);
	if (!line) return 0;

	y = get_textarea_line_number(line, fs->state);
	if (y == -1) {
		mem_free(line);
		return 0;
	}

	x = fs->state - line[y].start;

	mem_free(line);

	if (fc->wrap && x == fc->cols) x--;

	int_bounds(&fs->vpos, x - fc->cols + 1, x);
	int_bounds(&fs->vypos, y - fc->rows + 1, y);

	x -= fs->vpos;
	y -= fs->vypos;

	return y * fc->cols + x;
}
Exemple #2
0
int
area_cursor(struct form_control *fc, struct form_state *fs, int utf8)
{
	struct line_info *line;
	int x, y;

	assert(fc && fs);
	if_assert_failed return 0;

	if (utf8)
		line = format_textutf8(fs->value, fc->cols, fc->wrap, 0);
	else
		line = format_text(fs->value, fc->cols, fc->wrap, 0);

	if (!line) return 0;

	if (fs->state_cell)
		y = get_textarea_line_number(line, fs->state_cell);
	else
		y = get_textarea_line_number(line, fs->state);

	if (y == -1) {
		mem_free(line);
		return 0;
	}

	if (utf8) {
		if (fs->state_cell) {
			x = utf8_ptr2cells(fs->value + line[y].start,
					   fs->value + fs->state_cell);
			x += line[y].last_char_width;
		} else
			x = utf8_ptr2cells(fs->value + line[y].start,
					   fs->value + fs->state);
	} else {
		x = fs->state - line[y].start;
		if (fc->wrap && x == fc->cols) x--;
	}

	mem_free(line);

	int_bounds(&fs->vpos, x - fc->cols + 1, x);
	int_bounds(&fs->vypos, y - fc->rows + 1, y);

	x -= fs->vpos;
	y -= fs->vypos;

	return y * fc->cols + x;
}
Exemple #3
0
int
css_parse_font_weight_value(struct css_property_info *propinfo,
			    union css_property_value *value,
			    struct scanner *scanner)
{
	struct scanner_token *token = get_scanner_token(scanner);
	unsigned char *nstring;
	int weight;

	assert(propinfo->value_type == CSS_VT_FONT_ATTRIBUTE);

	if (token->type == CSS_TOKEN_IDENT) {
		if (scanner_token_contains(token, "bolder")) {
			value->font_attribute.add |= AT_BOLD;

		} else if (scanner_token_contains(token, "lighter")) {
			value->font_attribute.rem |= AT_BOLD;

		} else if (scanner_token_contains(token, "bold")) {
			value->font_attribute.add |= AT_BOLD;

		} else if (scanner_token_contains(token, "normal")) {
			value->font_attribute.rem |= AT_BOLD;

		} else {
			return 0;
		}

		skip_css_tokens(scanner, CSS_TOKEN_IDENT);
		return 1;
	}

	if (token->type != CSS_TOKEN_NUMBER) return 0;

	/* TODO: Comma separated list of weights?! */
	weight = strtol(token->string, (char **) &nstring, 10);
	if (token->string == nstring) return 0;

	skip_css_tokens(scanner, CSS_TOKEN_NUMBER);
	/* The font weight(s) have values between 100 to 900.  These
	 * values form an ordered sequence, where each number indicates
	 * a weight that is at least as dark as its predecessor.
	 *
	 * normal -> Same as '400'.  bold Same as '700'.
	 */
	int_bounds(&weight, 100, 900);
	if (weight >= 700) value->font_attribute.add |= AT_BOLD;
	return 1;
}
Exemple #4
0
void
dlg_format_group(struct dialog_data *dlg_data,
		 struct widget_data *widget_data,
		 int n, int x, int *y, int w, int *rw, int format_only)
{
	struct terminal *term = dlg_data->win->term;
	int space_between_widgets = 1;
	int line_width = 0;
	int xpos;
	struct color_pair *color = get_bfu_color(term, "dialog.text");

	assert(n > 0);
	if_assert_failed return;

	while (n--) {
		int widget_width;
		int width;
		unsigned char *text = widget_data->widget->text;
		int label_length;
		int label_padding;

#ifdef CONFIG_UTF8
		if (term->utf8_cp) {
			if (text && *text)
				label_length = utf8_ptr2cells(text, NULL);
			else
				label_length = 0;
		} else
#endif /* CONFIG_UTF8 */
			label_length = (text && *text) ? strlen(text) : 0;

		label_padding = (label_length > 0);

		if (widget_data->widget->type == WIDGET_CHECKBOX) {
			width = CHECKBOX_LEN;
		} else if (widget_is_textfield(widget_data)) {
#ifdef CONFIG_UTF8
			if (term->utf8_cp) {
				width = utf8_ptr2cells(widget_data->widget->data,
						       NULL);
			} else
#endif /* CONFIG_UTF8 */
				width = widget_data->widget->datalen;
		} else {
			/* TODO: handle all widget types. */
			widget_data++;
			continue;
		}

		int_bounds(&label_length, 0, w - width - label_padding);

		widget_width = width + label_padding + label_length;
		if (line_width + widget_width > w) {
			line_width = 0;
			(*y) += 2;	/* Next line */
		}

		xpos = x + line_width;

		if (!format_only) {
			if (widget_data->widget->type == WIDGET_CHECKBOX) {
				/* Draw text at right of checkbox. */
				if (label_length) {
#ifdef CONFIG_UTF8
					if (term->utf8_cp) {
						int lb = utf8_cells2bytes(
								text,
								label_length,
								NULL);
						draw_dlg_text(dlg_data, xpos + width
								+ label_padding,
							  *y, text, lb, 0,
							  color);
					} else
#endif /* CONFIG_UTF8 */
					{
						draw_dlg_text(dlg_data, xpos + width
								+ label_padding,
							  *y, text,
							  label_length, 0,
							  color);
					}
				}

				set_box(&widget_data->box, xpos, *y, width, 1);

			} else if (widget_is_textfield(widget_data)) {
				/* Draw label at left of widget. */
				if (label_length) {
#ifdef CONFIG_UTF8
					if (term->utf8_cp) {
						int lb = utf8_cells2bytes(
								text,
								label_length,
								NULL);
						draw_dlg_text(dlg_data, xpos, *y,
							  text, lb, 0, color);
					} else
#endif /* CONFIG_UTF8 */
					{
						draw_dlg_text(dlg_data, xpos, *y,
							  text, label_length,
							  0, color);
					}
				}

				set_box(&widget_data->box,
					xpos + label_padding + label_length, *y,
					width, 1);
			}
		}

		line_width += widget_width;
		if (rw) int_bounds(rw, line_width, w);
		line_width += space_between_widgets;

		widget_data++;
	}
	(*y)++;
}
Exemple #5
0
void
dlg_format_buttons(struct dialog_data *dlg_data,
		   struct widget_data *widget_data, int n,
		   int x, int *y, int w, int *rw, enum format_align align, int format_only)
{
#ifdef CONFIG_UTF8
	struct terminal *term = dlg_data->win->term;
#endif
	int i1 = 0;

	while (i1 < n) {
		struct widget_data *widget_data1 = widget_data + i1;
		int i2 = i1 + 1;
		int mw;

		while (i2 < n) {
			mw = 0;
#ifdef CONFIG_UTF8
			buttons_width(widget_data1, i2 - i1 + 1, NULL, &mw,
				      term->utf8_cp);
#else
			buttons_width(widget_data1, i2 - i1 + 1, NULL, &mw);
#endif /* CONFIG_UTF8 */
			if (mw <= w) i2++;
			else break;
		}

		mw = 0;
#ifdef CONFIG_UTF8
		buttons_width(widget_data1, i2 - i1, NULL, &mw, term->utf8_cp);
#else
		buttons_width(widget_data1, i2 - i1, NULL, &mw);
#endif /* CONFIG_UTF8 */
		if (rw) int_bounds(rw, mw, w);

		if (!format_only) {
			int i;
			int p = x + (align == ALIGN_CENTER ? (w - mw) / 2 : 0);
#ifdef CONFIG_UTF8
			int button_lr_len = utf8_ptr2cells(BUTTON_LEFT, NULL)
					  + utf8_ptr2cells(BUTTON_RIGHT, NULL);
#endif /* CONFIG_UTF8 */

			for (i = i1; i < i2; i++) {
#ifdef CONFIG_UTF8
				if (term->utf8_cp)
					set_box(&widget_data[i].box,
						p, *y,
						utf8_ptr2cells(widget_data[i].widget->text, NULL)
						+ button_lr_len, BUTTON_HEIGHT);
				else
#endif /* CONFIG_UTF8 */
					set_box(&widget_data[i].box,
						p, *y,
						widget_data[i].widget->info.button.textlen
						+ BUTTON_LR_LEN, BUTTON_HEIGHT);

				p += widget_data[i].box.width + BUTTON_HSPACING;
			}
		}

		*y += BUTTON_VSPACING + BUTTON_HEIGHT;
		i1 = i2;
	}
}
Exemple #6
0
void
dlg_format_group(struct terminal *term,
		 struct widget_data *widget_data,
		 int n, int x, int *y, int w, int *rw)
{
	int space_between_widgets = 1;
	int line_width = 0;
	int xpos;
	struct color_pair *color = get_bfu_color(term, "dialog.text");

	assert(n > 0);
	if_assert_failed return;

	while (n--) {
		int widget_width;
		int width;
		unsigned char *text = widget_data->widget->text;
		int label_length = (text && *text) ? strlen(text) : 0;
		int label_padding = (label_length > 0);

		if (widget_data->widget->type == WIDGET_CHECKBOX) {
			width = 3;
		} else if (widget_is_textfield(widget_data)) {
			width = widget_data->widget->datalen;
		} else {
			/* TODO: handle all widget types. */
			widget_data++;
			continue;
		}

		int_bounds(&label_length, 0, w - width - label_padding);

		widget_width = width + label_padding + label_length;
		if (line_width + widget_width > w) {
			line_width = 0;
			(*y) += 2;	/* Next line */
		}

		xpos = x + line_width;

		if (term) {
			if (widget_data->widget->type == WIDGET_CHECKBOX) {
				/* Draw text at right of checkbox. */
				if (label_length)
					draw_text(term, xpos + width + label_padding, *y,
						  text, label_length,
						  0, color);

				set_box(&widget_data->box, xpos, *y, width, 1);

			} else if (widget_is_textfield(widget_data)) {
				/* Draw label at left of widget. */
				if (label_length)
					draw_text(term, xpos, *y,
						  text, label_length,
						  0, color);

				set_box(&widget_data->box,
					xpos + label_padding + label_length, *y,
					width, 1);
			}
		}

		line_width += widget_width;
		if (rw) int_bounds(rw, line_width, w);
		line_width += space_between_widgets;

		widget_data++;
	}
	(*y)++;
}
Exemple #7
0
int
css_parse_color_value(struct css_property_info *propinfo,
		      union css_property_value *value,
		      struct scanner *scanner)
{
	struct scanner_token *token = get_scanner_token(scanner);

	assert(propinfo->value_type == CSS_VT_COLOR);

	if (token->type == CSS_TOKEN_RGB) {
		/* RGB function */
		int shift;

		token = get_next_scanner_token(scanner);

		/* First color component is shifted 16, next is shifted 8 and
		 * last is not shifted. */
		for (shift = 16; token && shift >= 0; shift -= 8) {
			/* The first two args are terminated by ',' and the
			 * last one by ')'. */
			unsigned char paskynator = shift ? ',' : ')';
			const unsigned char *nstring = token->string;
			int part;

			/* Are the current and next token valid? */
			if ((token->type != CSS_TOKEN_NUMBER
			     && token->type != CSS_TOKEN_PERCENTAGE)
			    || !check_next_scanner_token(scanner, paskynator))
				return 0;

			/* Parse the digit */
			part = strtol(token->string, (char **) &nstring, 10);
			if (token->string == nstring)
				return 0;

			/* Adjust percentage values */
			if (token->type == CSS_TOKEN_PERCENTAGE) {
				int_bounds(&part, 0, 100);
				part *= 255;
				part /= 100;
			}

			/* Adjust color component value and add it */
			int_bounds(&part, 0, 255);
			value->color |= part << shift;

			/* Paskynate the token arg and separator */
			token = skip_css_tokens(scanner, paskynator);
		}

		return 1;
	}

	/* Just a color value we already know how to parse. */
	if (token->type != CSS_TOKEN_IDENT
	    && token->type != CSS_TOKEN_HEX_COLOR)
		return 0;

	if (decode_color(token->string, token->length, &value->color) < 0) {
		return 0;
	}

	skip_css_tokens(scanner, token->type);
	return 1;
}