grafthistory: comment about downloading the pack index
[elinks/elinks-j605.git] / src / bfu / listbox.h
blob82fccd7814dd97d41c5528ab7d96a5d3dc8cd43c
1 #ifndef EL__BFU_LISTBOX_H
2 #define EL__BFU_LISTBOX_H
4 #include "util/align.h"
5 #include "util/lists.h"
7 struct dialog;
8 struct listbox_data;
9 struct listbox_item;
10 struct terminal;
11 struct uri;
12 struct widget_data;
14 struct widget_info_listbox {
15 int height;
19 void add_dlg_listbox(struct dialog *dlg, int height, void *box_data);
21 enum listbox_match {
22 LISTBOX_MATCH_OK,
23 LISTBOX_MATCH_NO,
24 LISTBOX_MATCH_IMPOSSIBLE,
27 /* Structure that can be used for storing all relevant info when traversing
28 * listboxes. */
29 struct listbox_context {
30 /* The terminal we are running on */
31 struct terminal *term;
33 /* Used for saving a specific item that should be used later when
34 * traversing listboxes has ended. */
35 struct listbox_item *item;
37 /* The current listbox widgets data */
38 struct listbox_data *box;
40 /* The current (hierbox browser) dialog stuff */
41 struct dialog_data *dlg_data;
42 struct widget_data *widget_data;
44 /* Used when distributing? the current selected to another position */
45 int dist;
47 /* The offset of the current box from the top */
48 int offset;
51 struct listbox_ops_messages {
52 unsigned char *cant_delete_item;
53 unsigned char *cant_delete_used_item;
54 unsigned char *cant_delete_folder;
55 unsigned char *cant_delete_used_folder;
56 unsigned char *delete_marked_items_title;
57 unsigned char *delete_marked_items;
58 unsigned char *delete_folder_title;
59 unsigned char *delete_folder;
60 unsigned char *delete_item_title;
61 unsigned char *delete_item;
62 unsigned char *clear_all_items_title;
63 unsigned char *clear_all_items;
66 /* TODO: We can maybe find a better way of figuring out whether a user of a
67 * generic button handler has implemented all the required functions. --jonas
68 * */
69 struct listbox_ops {
70 /* Some basic util/object.h wrappers */
71 void (*lock)(struct listbox_item *);
72 void (*unlock)(struct listbox_item *);
73 int (*is_used)(struct listbox_item *);
75 unsigned char *(*get_text)(struct listbox_item *, struct terminal *);
76 unsigned char *(*get_info)(struct listbox_item *, struct terminal *);
78 struct uri *(*get_uri)(struct listbox_item *);
80 struct listbox_item *(*get_root)(struct listbox_item *);
82 /* Do a search on the item. */
83 enum listbox_match (*match)(struct listbox_item *, struct terminal *,
84 unsigned char *text);
86 /* Before calling delete() thou shall call can_delete(). */
87 int (*can_delete)(struct listbox_item *);
89 /* Delete the listbox item object, its data and all nested listboxes.
90 * @last is non zero when either deleting only one item or when
91 * deleting the last item. */
92 void (*delete)(struct listbox_item *, int last);
94 /* If defined it means that the it will control all drawing of the
95 * listbox item text and what might else be possible on the screen on
96 * line @y from @x and @width chars onwards. */
97 void (*draw)(struct listbox_item *, struct listbox_context *,
98 int x, int y, int width);
100 struct listbox_ops_messages *messages;
103 /* Stores display information about a box. Kept in cdata. */
104 struct listbox_data {
105 LIST_HEAD(struct listbox_data);
107 struct listbox_ops *ops; /* Backend-provided operations */
108 struct listbox_item *sel; /* Item currently selected */
109 struct listbox_item *top; /* Item which is on the top line of the box */
111 int sel_offset; /* Offset of selected item against the box top */
112 struct list_head *items; /* The list being displayed */
115 enum listbox_item_type {
116 BI_LEAF,
117 BI_FOLDER,
118 BI_SEPARATOR
121 /* An item in a box */
122 struct listbox_item {
123 LIST_HEAD(struct listbox_item);
125 /* The list may be empty for leaf nodes or non-hiearchic listboxes */
126 struct list_head child;
128 enum listbox_item_type type;
129 int depth;
131 unsigned int expanded:1; /* Only valid if this is a BI_FOLDER */
132 unsigned int visible:1; /* Is this item visible? */
133 unsigned int marked:1;
135 void *udata;
138 extern struct widget_ops listbox_ops;
140 void dlg_format_listbox(struct terminal *, struct widget_data *, int, int *, int, int, int *, enum format_align);
142 struct listbox_item *traverse_listbox_items_list(struct listbox_item *, struct listbox_data *, int, int, int (*)(struct listbox_item *, void *, int *), void *);
144 void listbox_sel_move(struct widget_data *, int);
145 void listbox_sel(struct widget_data *widget_data, struct listbox_item *item);
146 struct listbox_data *get_listbox_widget_data(struct widget_data *widget_data);
148 #define get_dlg_listbox_data(dlg_data) \
149 get_listbox_widget_data(dlg_data->widgets_data)
151 #endif