test: The CGI script showing POST DATA sent to it.
[elinks.git] / src / bfu / listbox.h
blobbca2a26622c50273b7bf1dc3d30f1a2d6c16afe9
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;
15 void add_dlg_listbox(struct dialog *dlg, void *box_data);
17 enum listbox_match {
18 LISTBOX_MATCH_OK,
19 LISTBOX_MATCH_NO,
20 LISTBOX_MATCH_IMPOSSIBLE,
23 /* Structure that can be used for storing all relevant info when traversing
24 * listboxes. */
25 struct listbox_context {
26 /* The terminal we are running on */
27 struct terminal *term;
29 /* Used for saving a specific item that should be used later when
30 * traversing listboxes has ended. */
31 struct listbox_item *item;
33 /* The current listbox widgets data */
34 struct listbox_data *box;
36 /* The current (hierbox browser) dialog stuff */
37 struct dialog_data *dlg_data;
38 struct widget_data *widget_data;
40 /* Used when distributing? the current selected to another position */
41 int dist;
43 /* The offset of the current box from the top */
44 int offset;
47 struct listbox_ops_messages {
48 unsigned char *cant_delete_item; /* %s = text of item */
49 unsigned char *cant_delete_used_item; /* %s = text of item */
50 unsigned char *cant_delete_folder; /* %s = text of item */
51 unsigned char *cant_delete_used_folder; /* %s = text of item */
52 unsigned char *delete_marked_items_title; /* not a format string */
53 unsigned char *delete_marked_items; /* not a format string */
54 unsigned char *delete_folder_title; /* not a format string */
55 unsigned char *delete_folder; /* %s = text of item */
56 unsigned char *delete_item_title; /* not a format string */
57 unsigned char *delete_item; /* %s = text of item */
58 unsigned char *clear_all_items_title; /* not a format string */
59 unsigned char *clear_all_items; /* not a format string */
62 /* TODO: We can maybe find a better way of figuring out whether a user of a
63 * generic button handler has implemented all the required functions. --jonas
64 * */
65 struct listbox_ops {
66 /* Some basic util/object.h wrappers */
67 void (*lock)(struct listbox_item *);
68 void (*unlock)(struct listbox_item *);
69 int (*is_used)(struct listbox_item *);
71 unsigned char *(*get_text)(struct listbox_item *, struct terminal *);
72 unsigned char *(*get_info)(struct listbox_item *, struct terminal *);
74 struct uri *(*get_uri)(struct listbox_item *);
76 struct listbox_item *(*get_root)(struct listbox_item *);
78 /* Do a search on the item. */
79 enum listbox_match (*match)(struct listbox_item *, struct terminal *,
80 unsigned char *text);
82 /* Before calling delete() thou shall call can_delete(). */
83 int (*can_delete)(struct listbox_item *);
85 /* Delete the listbox item object, its data and all nested listboxes.
86 * @last is non zero when either deleting only one item or when
87 * deleting the last item. */
88 void (*delete)(struct listbox_item *, int last);
90 /* If defined it means that the it will control all drawing of the
91 * listbox item text and what might else be possible on the screen on
92 * line @y from @x and @width chars onwards. */
93 void (*draw)(struct listbox_item *, struct listbox_context *,
94 int x, int y, int width);
96 struct listbox_ops_messages *messages;
99 /* Stores display information about a box. Kept in cdata. */
100 struct listbox_data {
101 LIST_HEAD(struct listbox_data);
103 const struct listbox_ops *ops; /* Backend-provided operations */
104 struct listbox_item *sel; /* Item currently selected */
105 struct listbox_item *top; /* Item which is on the top line of the box */
107 int sel_offset; /* Offset of selected item against the box top */
108 struct list_head *items; /* The list being displayed */
111 enum listbox_item_type {
112 BI_LEAF,
113 BI_FOLDER,
114 BI_SEPARATOR
117 /* An item in a box */
118 struct listbox_item {
119 LIST_HEAD(struct listbox_item);
121 /* The list may be empty for leaf nodes or non-hiearchic listboxes */
122 struct list_head child;
124 enum listbox_item_type type;
125 int depth;
127 unsigned int expanded:1; /* Only valid if this is a BI_FOLDER */
128 unsigned int visible:1; /* Is this item visible? */
129 unsigned int marked:1;
131 void *udata;
134 extern const struct widget_ops listbox_ops;
136 void dlg_format_listbox(struct terminal *, struct widget_data *, int, int *, int, int, int *, enum format_align, int format_only);
138 struct listbox_item *traverse_listbox_items_list(struct listbox_item *, struct listbox_data *, int, int, int (*)(struct listbox_item *, void *, int *), void *);
140 void listbox_sel_move(struct widget_data *, int);
141 void listbox_sel(struct widget_data *widget_data, struct listbox_item *item);
142 struct listbox_data *get_listbox_widget_data(struct widget_data *widget_data);
144 #define get_dlg_listbox_data(dlg_data) \
145 get_listbox_widget_data(dlg_data->widgets_data)
147 #endif