1
2
3
4
5
6
7
8
9#include <sys/types.h>
10#include <fcntl.h>
11#include <unistd.h>
12#include <ctype.h>
13#include <stdlib.h>
14#include <string.h>
15#include <stdbool.h>
16
17#ifndef KBUILD_NO_NLS
18# include <libintl.h>
19#else
20# define gettext(Msgid) ((const char *) (Msgid))
21#endif
22
23#ifdef __sun__
24#define CURS_MACROS
25#endif
26#include CURSES_LOC
27
28
29
30
31
32
33
34
35
36#if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
37#define OLD_NCURSES 1
38#undef wbkgdset
39#define wbkgdset(w,p)
40#else
41#define OLD_NCURSES 0
42#endif
43
44#define TR(params) _tracef params
45
46#define KEY_ESC 27
47#define TAB 9
48#define MAX_LEN 2048
49#define BUF_SIZE (10*1024)
50#define MIN(x,y) (x < y ? x : y)
51#define MAX(x,y) (x > y ? x : y)
52
53#ifndef ACS_ULCORNER
54#define ACS_ULCORNER '+'
55#endif
56#ifndef ACS_LLCORNER
57#define ACS_LLCORNER '+'
58#endif
59#ifndef ACS_URCORNER
60#define ACS_URCORNER '+'
61#endif
62#ifndef ACS_LRCORNER
63#define ACS_LRCORNER '+'
64#endif
65#ifndef ACS_HLINE
66#define ACS_HLINE '-'
67#endif
68#ifndef ACS_VLINE
69#define ACS_VLINE '|'
70#endif
71#ifndef ACS_LTEE
72#define ACS_LTEE '+'
73#endif
74#ifndef ACS_RTEE
75#define ACS_RTEE '+'
76#endif
77#ifndef ACS_UARROW
78#define ACS_UARROW '^'
79#endif
80#ifndef ACS_DARROW
81#define ACS_DARROW 'v'
82#endif
83
84
85#define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
86
87
88
89
90struct dialog_color {
91 chtype atr;
92 int fg;
93 int bg;
94 int hl;
95};
96
97struct subtitle_list {
98 struct subtitle_list *next;
99 const char *text;
100};
101
102struct dialog_info {
103 const char *backtitle;
104 struct subtitle_list *subtitles;
105 struct dialog_color screen;
106 struct dialog_color shadow;
107 struct dialog_color dialog;
108 struct dialog_color title;
109 struct dialog_color border;
110 struct dialog_color button_active;
111 struct dialog_color button_inactive;
112 struct dialog_color button_key_active;
113 struct dialog_color button_key_inactive;
114 struct dialog_color button_label_active;
115 struct dialog_color button_label_inactive;
116 struct dialog_color inputbox;
117 struct dialog_color inputbox_border;
118 struct dialog_color searchbox;
119 struct dialog_color searchbox_title;
120 struct dialog_color searchbox_border;
121 struct dialog_color position_indicator;
122 struct dialog_color menubox;
123 struct dialog_color menubox_border;
124 struct dialog_color item;
125 struct dialog_color item_selected;
126 struct dialog_color tag;
127 struct dialog_color tag_selected;
128 struct dialog_color tag_key;
129 struct dialog_color tag_key_selected;
130 struct dialog_color check;
131 struct dialog_color check_selected;
132 struct dialog_color uarrow;
133 struct dialog_color darrow;
134};
135
136
137
138
139extern struct dialog_info dlg;
140extern char dialog_input_result[];
141extern int saved_x, saved_y;
142
143
144
145
146
147
148void item_reset(void);
149void item_make(const char *fmt, ...);
150void item_add_str(const char *fmt, ...);
151void item_set_tag(char tag);
152void item_set_data(void *p);
153void item_set_selected(int val);
154int item_activate_selected(void);
155void *item_data(void);
156char item_tag(void);
157
158
159#define MAXITEMSTR 200
160struct dialog_item {
161 char str[MAXITEMSTR];
162 char tag;
163 void *data;
164 int selected;
165};
166
167
168struct dialog_list {
169 struct dialog_item node;
170 struct dialog_list *next;
171};
172
173extern struct dialog_list *item_cur;
174extern struct dialog_list item_nil;
175extern struct dialog_list *item_head;
176
177int item_count(void);
178void item_set(int n);
179int item_n(void);
180const char *item_str(void);
181int item_is_selected(void);
182int item_is_tag(char tag);
183#define item_foreach() \
184 for (item_cur = item_head ? item_head: item_cur; \
185 item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
186
187
188int on_key_esc(WINDOW *win);
189int on_key_resize(void);
190
191
192#define CHECKLIST_HEIGTH_MIN 6
193#define CHECKLIST_WIDTH_MIN 6
194#define INPUTBOX_HEIGTH_MIN 2
195#define INPUTBOX_WIDTH_MIN 2
196#define MENUBOX_HEIGTH_MIN 15
197#define MENUBOX_WIDTH_MIN 65
198#define TEXTBOX_HEIGTH_MIN 8
199#define TEXTBOX_WIDTH_MIN 8
200#define YESNO_HEIGTH_MIN 4
201#define YESNO_WIDTH_MIN 4
202#define WINDOW_HEIGTH_MIN 19
203#define WINDOW_WIDTH_MIN 80
204
205int init_dialog(const char *backtitle);
206void set_dialog_backtitle(const char *backtitle);
207void set_dialog_subtitles(struct subtitle_list *subtitles);
208void end_dialog(int x, int y);
209void attr_clear(WINDOW * win, int height, int width, chtype attr);
210void dialog_clear(void);
211void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
212void print_button(WINDOW * win, const char *label, int y, int x, int selected);
213void print_title(WINDOW *dialog, const char *title, int width);
214void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
215 chtype border);
216void draw_shadow(WINDOW * win, int y, int x, int height, int width);
217
218int first_alpha(const char *string, const char *exempt);
219int dialog_yesno(const char *title, const char *prompt, int height, int width);
220int dialog_msgbox(const char *title, const char *prompt, int height,
221 int width, int pause);
222
223
224typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void
225 *_data);
226int dialog_textbox(const char *title, char *tbuf, int initial_height,
227 int initial_width, int *keys, int *_vscroll, int *_hscroll,
228 update_text_fn update_text, void *data);
229int dialog_menu(const char *title, const char *prompt,
230 const void *selected, int *s_scroll);
231int dialog_checklist(const char *title, const char *prompt, int height,
232 int width, int list_height);
233int dialog_inputbox(const char *title, const char *prompt, int height,
234 int width, const char *init);
235
236
237
238
239
240
241
242
243
244
245#define M_EVENT (KEY_MAX+1)
246