void empty_window_handler(struct window *win, struct event *ev, int fwd) { struct window *n; struct ewd *ewd = win->data; int x, y; void (*fn)(void *) = ewd->fn; void *data = ewd->data; if (ewd->b) return; switch ((int)ev->ev) { case EV_INIT: case EV_RESIZE: case EV_REDRAW: get_parent_ptr(win, &x, &y); set_window_ptr(win, x, y); return; case EV_ABORT: fn(data); return; } ewd->b = 1; n = win->next; delete_window(win); fn(data); if (n->next != n) n->handler(n, ev, fwd); }
/* Takes care about rendering of each listbox item. */ static int display_listbox_item(struct listbox_item *item, void *data_, int *offset) { struct listbox_context *data = (struct listbox_context *)data_; int len; /* Length of the current text field. */ struct color_pair *tree_color, *text_color; int depth = item->depth + 1; int d; int x, y; tree_color = get_bfu_color(data->term, (const unsigned char *)"menu.normal"); if (item == data->box->sel) { text_color = get_bfu_color(data->term, (const unsigned char *)"menu.selected"); } else if (item->marked) { text_color = get_bfu_color(data->term, (const unsigned char *)"menu.marked"); } else { text_color = tree_color; } y = data->widget_data->box.y + data->offset; for (d = 0; d < depth - 1; d++) { struct listbox_item *root = item; struct listbox_item *child = item; int i, x; for (i = depth - d; i; i--) { child = root; if (root) root = data->box->ops->get_root(root); } /* XXX */ x = data->widget_data->box.x + d * 5; draw_text(data->term, x, y, (const unsigned char *)" ", 5, 0, tree_color); if (root ? root->child.prev == child : data->box->items->prev == child) continue; /* We were the last branch. */ draw_border_char(data->term, x + 1, y, BORDER_SVLINE, tree_color); } if (depth) { unsigned char str[5] = { 32, BORDER_SRTEE, BORDER_SHLINE, BORDER_SHLINE, 32 }; int i; switch (item->type) { case BI_LEAF: case BI_SEPARATOR: { const struct listbox_item *prev; prev = traverse_listbox_items_list(item, data->box, -1, 1, NULL, NULL); if (item == prev) { /* There is no visible item before @item, so it * must be the first item in the listbox. */ str[1] = BORDER_SULCORNER; } else { const struct listbox_item *next; next = traverse_listbox_items_list(item, data->box, 1, 1, NULL, NULL); if (item == next || item->depth != next->depth) { /* There is no visible item after @item * at the same depth, so it must be the * last in its folder. */ str[1] = BORDER_SDLCORNER; } } break; } case BI_FOLDER: str[0] = '['; str[1] = (item->expanded) ? '-' : '+'; str[2] = ']'; break; default: INTERNAL("Unknown item type"); break; } if (item->marked) str[4] = '*'; x = data->widget_data->box.x + (depth - 1) * 5; for (i = 0; i < 5; i++) { draw_border_char(data->term, x + i, y, str[i], tree_color); } } x = data->widget_data->box.x + depth * 5; if (item->type == BI_SEPARATOR) { int i; int width = data->widget_data->box.width - depth * 5; for (i = 0; i < width; i++) { draw_border_char(data->term, x + i, y, BORDER_SHLINE, text_color); } } else if (data->box->ops && data->box->ops->draw) { int width = data->widget_data->box.width - depth * 5; data->box->ops->draw(item, data, x, y, width); } else { unsigned char *text; const struct listbox_ops *ops = data->box->ops; int len_bytes; assert(ops && ops->get_info); text = ops->get_text(item, data->term); if (!text) return 0; len = strlen((const char *)text); int_upper_bound(&len, int_max(0, data->widget_data->box.width - depth * 5)); #ifdef CONFIG_UTF8 if (data->term->utf8_cp) len_bytes = utf8_cells2bytes(text, len, NULL); else #endif /* CONFIG_UTF8 */ len_bytes = len; draw_text(data->term, x, y, text, len_bytes, 0, text_color); mem_free(text); } if (item == data->box->sel) { /* For blind users: */ x = data->widget_data->box.x + 5 + item->depth * 5; set_cursor(data->term, x, y, 1); set_window_ptr(data->dlg_data->win, x, y); } data->offset++; return 0; }