WLEntry * listbox_get_nth_item (const WListbox * l, int pos) { if (!listbox_is_empty (l) && pos >= 0) { GList *item; item = g_queue_peek_nth_link (l->list, (guint) pos); if (item != NULL) return LENTRY (item->data); } return NULL; }
int listbox_search_text (WListbox * l, const char *text) { if (!listbox_is_empty (l)) { int i; GList *le; for (i = 0, le = g_queue_peek_head_link (l->list); le != NULL; i++, le = g_list_next (le)) { WLEntry *e = LENTRY (le->data); if (strcmp (e->text, text) == 0) return i; } } return (-1); }
static int listbox_check_hotkey (WListbox * l, int key) { if (!listbox_is_empty (l)) { int i; GList *le; for (i = 0, le = g_queue_peek_head_link (l->list); le != NULL; i++, le = g_list_next (le)) { WLEntry *e = LENTRY (le->data); if (e->hotkey == key) return i; } } return (-1); }
/** * Finds item by its 'data' slot. */ int listbox_search_data (WListbox * l, const void *data) { if (!listbox_is_empty (l)) { int i; GList *le; for (i = 0, le = g_queue_peek_head_link (l->list); le != NULL; i++, le = g_list_next (le)) { WLEntry *e = LENTRY (le->data); if (e->data == data) return i; } } return (-1); }
void listbox_remove_current (WListbox * l) { if (!listbox_is_empty (l)) { GList *current; int length; current = g_queue_peek_nth_link (l->list, (guint) l->pos); listbox_entry_free (LENTRY (current->data)); g_queue_delete_link (l->list, current); length = g_queue_get_length (l->list); if (length == 0) l->top = l->pos = 0; else if (l->pos >= length) l->pos = length - 1; } }
static void listbox_draw (WListbox * l, gboolean focused) { Widget *w = WIDGET (l); const WDialog *h = w->owner; const gboolean disabled = (w->options & W_DISABLED) != 0; const int normalc = disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]; /* *INDENT-OFF* */ int selc = disabled ? DISABLED_COLOR : focused ? h->color[DLG_COLOR_HOT_FOCUS] : h->color[DLG_COLOR_FOCUS]; /* *INDENT-ON* */ int length = 0; GList *le = NULL; int pos; int i; int sel_line = -1; if (l->list != NULL) { length = g_queue_get_length (l->list); le = g_queue_peek_nth_link (l->list, (guint) l->top); } /* pos = (le == NULL) ? 0 : g_list_position (l->list, le); */ pos = (le == NULL) ? 0 : l->top; for (i = 0; i < w->lines; i++) { const char *text = ""; /* Display the entry */ if (pos == l->pos && sel_line == -1) { sel_line = i; tty_setcolor (selc); } else tty_setcolor (normalc); widget_move (l, i, 1); if (l->list != NULL && le != NULL && (i == 0 || pos < length)) { WLEntry *e = LENTRY (le->data); text = e->text; le = g_list_next (le); pos++; } tty_print_string (str_fit_to_term (text, w->cols - 2, J_LEFT_FIT)); } l->cursor_y = sel_line; if (l->scrollbar && length > w->lines) { tty_setcolor (normalc); listbox_drawscroll (l); } }