yann@1
|
1 |
/*
|
yann@1
|
2 |
* dialog.h -- common declarations for all dialog modules
|
yann@1
|
3 |
*
|
yann@1
|
4 |
* AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
|
yann@1
|
5 |
*
|
yann@1
|
6 |
* This program is free software; you can redistribute it and/or
|
yann@1
|
7 |
* modify it under the terms of the GNU General Public License
|
yann@1
|
8 |
* as published by the Free Software Foundation; either version 2
|
yann@1
|
9 |
* of the License, or (at your option) any later version.
|
yann@1
|
10 |
*
|
yann@1
|
11 |
* This program is distributed in the hope that it will be useful,
|
yann@1
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yann@1
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
yann@1
|
14 |
* GNU General Public License for more details.
|
yann@1
|
15 |
*
|
yann@1
|
16 |
* You should have received a copy of the GNU General Public License
|
yann@1
|
17 |
* along with this program; if not, write to the Free Software
|
yann@1
|
18 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
yann@1
|
19 |
*/
|
yann@1
|
20 |
|
yann@1
|
21 |
#include <sys/types.h>
|
yann@1
|
22 |
#include <fcntl.h>
|
yann@1
|
23 |
#include <unistd.h>
|
yann@1
|
24 |
#include <ctype.h>
|
yann@1
|
25 |
#include <stdlib.h>
|
yann@1
|
26 |
#include <string.h>
|
yann@1
|
27 |
#include <stdbool.h>
|
yann@1
|
28 |
|
yann@1
|
29 |
#ifdef __sun__
|
yann@1
|
30 |
#define CURS_MACROS
|
yann@1
|
31 |
#endif
|
yann@1
|
32 |
#include CURSES_LOC
|
yann@1
|
33 |
|
yann@1
|
34 |
/*
|
yann@1
|
35 |
* Colors in ncurses 1.9.9e do not work properly since foreground and
|
yann@1
|
36 |
* background colors are OR'd rather than separately masked. This version
|
yann@1
|
37 |
* of dialog was hacked to work with ncurses 1.9.9e, making it incompatible
|
yann@1
|
38 |
* with standard curses. The simplest fix (to make this work with standard
|
yann@1
|
39 |
* curses) uses the wbkgdset() function, not used in the original hack.
|
yann@1
|
40 |
* Turn it off if we're building with 1.9.9e, since it just confuses things.
|
yann@1
|
41 |
*/
|
yann@1
|
42 |
#if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
|
yann@1
|
43 |
#define OLD_NCURSES 1
|
yann@1
|
44 |
#undef wbkgdset
|
yann@1
|
45 |
#define wbkgdset(w,p) /*nothing */
|
yann@1
|
46 |
#else
|
yann@1
|
47 |
#define OLD_NCURSES 0
|
yann@1
|
48 |
#endif
|
yann@1
|
49 |
|
yann@1
|
50 |
#define TR(params) _tracef params
|
yann@1
|
51 |
|
yann@1
|
52 |
#define KEY_ESC 27
|
yann@1
|
53 |
#define TAB 9
|
yann@1
|
54 |
#define MAX_LEN 2048
|
yann@1
|
55 |
#define BUF_SIZE (10*1024)
|
yann@1
|
56 |
#define MIN(x,y) (x < y ? x : y)
|
yann@1
|
57 |
#define MAX(x,y) (x > y ? x : y)
|
yann@1
|
58 |
|
yann@1
|
59 |
#ifndef ACS_ULCORNER
|
yann@1
|
60 |
#define ACS_ULCORNER '+'
|
yann@1
|
61 |
#endif
|
yann@1
|
62 |
#ifndef ACS_LLCORNER
|
yann@1
|
63 |
#define ACS_LLCORNER '+'
|
yann@1
|
64 |
#endif
|
yann@1
|
65 |
#ifndef ACS_URCORNER
|
yann@1
|
66 |
#define ACS_URCORNER '+'
|
yann@1
|
67 |
#endif
|
yann@1
|
68 |
#ifndef ACS_LRCORNER
|
yann@1
|
69 |
#define ACS_LRCORNER '+'
|
yann@1
|
70 |
#endif
|
yann@1
|
71 |
#ifndef ACS_HLINE
|
yann@1
|
72 |
#define ACS_HLINE '-'
|
yann@1
|
73 |
#endif
|
yann@1
|
74 |
#ifndef ACS_VLINE
|
yann@1
|
75 |
#define ACS_VLINE '|'
|
yann@1
|
76 |
#endif
|
yann@1
|
77 |
#ifndef ACS_LTEE
|
yann@1
|
78 |
#define ACS_LTEE '+'
|
yann@1
|
79 |
#endif
|
yann@1
|
80 |
#ifndef ACS_RTEE
|
yann@1
|
81 |
#define ACS_RTEE '+'
|
yann@1
|
82 |
#endif
|
yann@1
|
83 |
#ifndef ACS_UARROW
|
yann@1
|
84 |
#define ACS_UARROW '^'
|
yann@1
|
85 |
#endif
|
yann@1
|
86 |
#ifndef ACS_DARROW
|
yann@1
|
87 |
#define ACS_DARROW 'v'
|
yann@1
|
88 |
#endif
|
yann@1
|
89 |
|
yann@1
|
90 |
/* error return codes */
|
yann@1
|
91 |
#define ERRDISPLAYTOOSMALL (KEY_MAX + 1)
|
yann@1
|
92 |
|
yann@1
|
93 |
/*
|
yann@1
|
94 |
* Color definitions
|
yann@1
|
95 |
*/
|
yann@1
|
96 |
struct dialog_color {
|
yann@1
|
97 |
chtype atr; /* Color attribute */
|
yann@1
|
98 |
int fg; /* foreground */
|
yann@1
|
99 |
int bg; /* background */
|
yann@1
|
100 |
int hl; /* highlight this item */
|
yann@1
|
101 |
};
|
yann@1
|
102 |
|
yann@1
|
103 |
struct dialog_info {
|
yann@1
|
104 |
const char *backtitle;
|
yann@1
|
105 |
struct dialog_color screen;
|
yann@1
|
106 |
struct dialog_color shadow;
|
yann@1
|
107 |
struct dialog_color dialog;
|
yann@1
|
108 |
struct dialog_color title;
|
yann@1
|
109 |
struct dialog_color border;
|
yann@1
|
110 |
struct dialog_color button_active;
|
yann@1
|
111 |
struct dialog_color button_inactive;
|
yann@1
|
112 |
struct dialog_color button_key_active;
|
yann@1
|
113 |
struct dialog_color button_key_inactive;
|
yann@1
|
114 |
struct dialog_color button_label_active;
|
yann@1
|
115 |
struct dialog_color button_label_inactive;
|
yann@1
|
116 |
struct dialog_color inputbox;
|
yann@1
|
117 |
struct dialog_color inputbox_border;
|
yann@1
|
118 |
struct dialog_color searchbox;
|
yann@1
|
119 |
struct dialog_color searchbox_title;
|
yann@1
|
120 |
struct dialog_color searchbox_border;
|
yann@1
|
121 |
struct dialog_color position_indicator;
|
yann@1
|
122 |
struct dialog_color menubox;
|
yann@1
|
123 |
struct dialog_color menubox_border;
|
yann@1
|
124 |
struct dialog_color item;
|
yann@1
|
125 |
struct dialog_color item_selected;
|
yann@1
|
126 |
struct dialog_color tag;
|
yann@1
|
127 |
struct dialog_color tag_selected;
|
yann@1
|
128 |
struct dialog_color tag_key;
|
yann@1
|
129 |
struct dialog_color tag_key_selected;
|
yann@1
|
130 |
struct dialog_color check;
|
yann@1
|
131 |
struct dialog_color check_selected;
|
yann@1
|
132 |
struct dialog_color uarrow;
|
yann@1
|
133 |
struct dialog_color darrow;
|
yann@1
|
134 |
};
|
yann@1
|
135 |
|
yann@1
|
136 |
/*
|
yann@1
|
137 |
* Global variables
|
yann@1
|
138 |
*/
|
yann@1
|
139 |
extern struct dialog_info dlg;
|
yann@1
|
140 |
extern char dialog_input_result[];
|
yann@1
|
141 |
|
yann@1
|
142 |
/*
|
yann@1
|
143 |
* Function prototypes
|
yann@1
|
144 |
*/
|
yann@1
|
145 |
|
yann@1
|
146 |
/* item list as used by checklist and menubox */
|
yann@1
|
147 |
void item_reset(void);
|
yann@1
|
148 |
void item_make(const char *fmt, ...);
|
yann@1
|
149 |
void item_add_str(const char *fmt, ...);
|
yann@1
|
150 |
void item_set_tag(char tag);
|
yann@1
|
151 |
void item_set_data(void *p);
|
yann@1
|
152 |
void item_set_selected(int val);
|
yann@1
|
153 |
int item_activate_selected(void);
|
yann@1
|
154 |
void *item_data(void);
|
yann@1
|
155 |
char item_tag(void);
|
yann@1
|
156 |
|
yann@1
|
157 |
/* item list manipulation for lxdialog use */
|
yann@1
|
158 |
#define MAXITEMSTR 200
|
yann@1
|
159 |
struct dialog_item {
|
yann@1
|
160 |
char str[MAXITEMSTR]; /* promtp displayed */
|
yann@1
|
161 |
char tag;
|
yann@1
|
162 |
void *data; /* pointer to menu item - used by menubox+checklist */
|
yann@1
|
163 |
int selected; /* Set to 1 by dialog_*() function if selected. */
|
yann@1
|
164 |
};
|
yann@1
|
165 |
|
yann@1
|
166 |
/* list of lialog_items */
|
yann@1
|
167 |
struct dialog_list {
|
yann@1
|
168 |
struct dialog_item node;
|
yann@1
|
169 |
struct dialog_list *next;
|
yann@1
|
170 |
};
|
yann@1
|
171 |
|
yann@1
|
172 |
extern struct dialog_list *item_cur;
|
yann@1
|
173 |
extern struct dialog_list item_nil;
|
yann@1
|
174 |
extern struct dialog_list *item_head;
|
yann@1
|
175 |
|
yann@1
|
176 |
int item_count(void);
|
yann@1
|
177 |
void item_set(int n);
|
yann@1
|
178 |
int item_n(void);
|
yann@1
|
179 |
const char *item_str(void);
|
yann@1
|
180 |
int item_is_selected(void);
|
yann@1
|
181 |
int item_is_tag(char tag);
|
yann@1
|
182 |
#define item_foreach() \
|
yann@1
|
183 |
for (item_cur = item_head ? item_head: item_cur; \
|
yann@1
|
184 |
item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
|
yann@1
|
185 |
|
yann@1
|
186 |
/* generic key handlers */
|
yann@1
|
187 |
int on_key_esc(WINDOW *win);
|
yann@1
|
188 |
int on_key_resize(void);
|
yann@1
|
189 |
|
yann@1
|
190 |
void init_dialog(const char *backtitle);
|
yann@1
|
191 |
void reset_dialog(void);
|
yann@1
|
192 |
void end_dialog(void);
|
yann@1
|
193 |
void attr_clear(WINDOW * win, int height, int width, chtype attr);
|
yann@1
|
194 |
void dialog_clear(void);
|
yann@1
|
195 |
void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
|
yann@1
|
196 |
void print_button(WINDOW * win, const char *label, int y, int x, int selected);
|
yann@1
|
197 |
void print_title(WINDOW *dialog, const char *title, int width);
|
yann@1
|
198 |
void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
|
yann@1
|
199 |
chtype border);
|
yann@1
|
200 |
void draw_shadow(WINDOW * win, int y, int x, int height, int width);
|
yann@1
|
201 |
|
yann@1
|
202 |
int first_alpha(const char *string, const char *exempt);
|
yann@1
|
203 |
int dialog_yesno(const char *title, const char *prompt, int height, int width);
|
yann@1
|
204 |
int dialog_msgbox(const char *title, const char *prompt, int height,
|
yann@1
|
205 |
int width, int pause);
|
yann@1
|
206 |
int dialog_textbox(const char *title, const char *file, int height, int width);
|
yann@1
|
207 |
int dialog_menu(const char *title, const char *prompt,
|
yann@1
|
208 |
const void *selected, int *s_scroll);
|
yann@1
|
209 |
int dialog_checklist(const char *title, const char *prompt, int height,
|
yann@1
|
210 |
int width, int list_height);
|
yann@1
|
211 |
extern char dialog_input_result[];
|
yann@1
|
212 |
int dialog_inputbox(const char *title, const char *prompt, int height,
|
yann@1
|
213 |
int width, const char *init);
|
yann@1
|
214 |
|
yann@1
|
215 |
/*
|
yann@1
|
216 |
* This is the base for fictitious keys, which activate
|
yann@1
|
217 |
* the buttons.
|
yann@1
|
218 |
*
|
yann@1
|
219 |
* Mouse-generated keys are the following:
|
yann@1
|
220 |
* -- the first 32 are used as numbers, in addition to '0'-'9'
|
yann@1
|
221 |
* -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o')
|
yann@1
|
222 |
* -- uppercase chars are used to invoke the button (M_EVENT + 'O')
|
yann@1
|
223 |
*/
|
yann@1
|
224 |
#define M_EVENT (KEY_MAX+1)
|