Пример #1
0
void
curses_form_finalize(struct curses_form *cf)
{
	if (cf->widget_head != NULL) {
		cf->widget_focus = cf->widget_head;
		curses_form_focus_skip_forward(cf);
		cf->want_x = cf->widget_focus->x + cf->widget_focus->width / 2;
		cf->want_y = cf->widget_focus->y;
	} else {
		cf->widget_focus = NULL;
	}

	cf->left = (xmax - cf->width) / 2;
	cf->top  = (ymax - cf->height) / 2;

	/*
	 * Set the internal width and height.
	 */
	
	cf->int_width = cf->width;
	cf->int_height = cf->height;

	/*
	 * Limit form size to physical screen dimensions.
	 */
	if (cf->width > (xmax - 2)) {
		cf->width = xmax - 2;
		cf->left = 1;
	}
	if (cf->height > (ymax - 2)) {
		cf->height = ymax - 2;
		cf->top = 1;
	}
	if (cf->top < 1)
		cf->top = 1;
	if (cf->left < 1)
		cf->left = 1;

	cf->win = newwin(cf->height + 2, cf->width + 2, cf->top - 1, cf->left - 1);
	if (cf->win == NULL)
		fprintf(stderr, "Could not allocate %dx%d window @ %d,%d\n",
		    cf->width + 2, cf->height + 2, cf->left - 1, cf->top - 1);

	cf->pan = new_panel(cf->win);
}
Пример #2
0
/*
 * Callback to give to curses_widget_set_click_cb, for buttons
 * that remove the same row of widgets that they are on.
 */
static int
cb_click_remove_row(struct curses_widget *w)
{
	struct curses_form *cf = w->form;
	struct curses_widget *few;
	int id = w->user_id;

	/*
	 * Since we're going to be deleting the widget with
	 * the focus, first move the focus onto a widget
	 * that we won't be deleting.
	 */
	do {
		if (cf->widget_focus == NULL)
			cf->widget_focus = cf->widget_head;
		while (cf->widget_focus->user_id == id)
			cf->widget_focus = cf->widget_focus->prev;
	} while (cf->widget_focus == NULL);

	/*
	 * Delete all widgets with the same id as the focused one.
	 */
	for (few = cf->widget_head; few != NULL; few = few->next) {
		if (few->user_id == id) {
			curses_form_widget_remove(few);
			/*
			 * Reset the iterator, as the previous command
			 * may have obliterated the current widget.
			 */
			few = cf->widget_head;
		}
	}

	/*
	 * Slide the remaining widgets up a row.
	 */
	for (few = cf->widget_head; few != NULL; few = few->next) {
		if (few->user_id > id) {
			/*
			 * Slide the rows below the deleted row up one row.
			 */
			few->user_id--;
			few->y--;
		} else if (few->user_id == -1) {
			/*
			 * Slide the buttons, too.
			 */
			few->y--;
		}
	}

	cf->int_height--;

	/*
	 * Now that the widgets are deleted, make sure the focus is
	 * on a usable widget (not a label.)
	 */
	curses_form_focus_skip_forward(cf);
	cf->want_y = cf->widget_focus->y;

	/*
	 * Repaint the form.  XXX Might not be necessary anymore?
	 */
	curses_form_draw(cf);
	curses_form_refresh(cf);
	return(0);
}