Document add_dlg_button, add_dlg_ok_button
[elinks.git] / src / bfu / button.h
bloba1a46cf58089e7529b94df9345b17c6cd8111027
1 #ifndef EL__BFU_BUTTON_H
2 #define EL__BFU_BUTTON_H
4 #include "bfu/common.h"
5 #include "util/align.h"
7 struct dialog;
8 struct terminal;
9 struct widget_data;
11 typedef void (done_handler_T)(void *);
13 struct widget_info_button {
14 int flags;
15 int hotkey_pos; /* -1 means no hotkey, hotkeys are marked by ~. */
16 int textlen; /* Text length without hotkey */
17 int truetextlen; /* Original text length (with hotkey if any) */
18 /* Used by some default handlers like ok_dialog()
19 * as a callback. */
20 done_handler_T *done;
21 void *done_data;
24 /* Button flags, go into widget.gid */
25 #define B_ENTER 1
26 #define B_ESC 2
28 /* Define to find buttons without keyboard accelerator. */
29 /* #define DEBUG_BUTTON_HOTKEY */
31 /** @def add_dlg_ok_button
32 * Add a button that will close the dialog if pressed.
34 * void add_dlg_ok_button(struct dialog *dlg, unsigned char *text, int flags,
35 * ::done_handler_T *done, void *done_data);
37 * @param dlg
38 * The dialog in which the button is to be added.
40 * @param text
41 * Text displayed in the button. This string should contain a
42 * keyboard accelerator, marked with a preceding '~'. The pointer
43 * must remain valid as long as the dialog exists.
45 * @param flags
46 * Can be ::B_ENTER, ::B_ESC, or 0.
48 * @param done
49 * A function that BFU calls when the user presses this button.
50 * Before calling this, BFU checks the values of widgets.
51 * After the function returns, BFU closes the dialog.
53 * @param done_data
54 * A pointer to be passed to the @a done callback. */
56 /** @def add_dlg_button
57 * Add a button that need not close the dialog if pressed.
59 * void add_dlg_button(struct dialog *dlg, unsigned char *text, int flags,
60 * ::widget_handler_t *handler, void *data);
62 * @param handler
63 * A function that BFU calls when the user presses this button.
64 * BFU does not automatically check the values of widgets
65 * or close the dialog.
67 * @param data
68 * A pointer to any data needed by @a handler. It does not get this
69 * pointer as a parameter but can read it from widget_data->widget->data.
71 * The other parameters are as in ::add_dlg_ok_button. */
73 #ifdef DEBUG_BUTTON_HOTKEY
74 void add_dlg_button_do(const unsigned char *file, int line, struct dialog *dlg, unsigned char *text, int flags, widget_handler_T *handler, void *data, done_handler_T *done, void *done_data);
75 #define add_dlg_ok_button(dlg, text, flags, done, data) \
76 add_dlg_button_do(__FILE__, __LINE__, dlg, text, flags, ok_dialog, NULL, done, data)
78 #define add_dlg_button(dlg, text, flags, handler, data) \
79 add_dlg_button_do(__FILE__, __LINE__, dlg, text, flags, handler, data, NULL, NULL)
81 #else
82 void add_dlg_button_do(struct dialog *dlg, unsigned char *text, int flags, widget_handler_T *handler, void *data, done_handler_T *done, void *done_data);
84 #define add_dlg_ok_button(dlg, text, flags, done, data) \
85 add_dlg_button_do(dlg, text, flags, ok_dialog, NULL, done, data)
87 #define add_dlg_button(dlg, text, flags, handler, data) \
88 add_dlg_button_do(dlg, text, flags, handler, data, NULL, NULL)
89 #endif
91 extern const struct widget_ops button_ops;
92 void dlg_format_buttons(struct terminal *, struct widget_data *, int, int, int *, int, int *, enum format_align, int);
94 #endif