utils:libgpo: re-add libgpo as library, it should not be part of gpext
[garming/samba-autobuild/.git] / source3 / utils / regedit_dialog.h
1 /*
2  * Samba Unix/Linux SMB client library
3  * Registry Editor
4  * Copyright (C) Christopher Davis 2012
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #ifndef _REGEDIT_DIALOG_H_
21 #define _REGEDIT_DIALOG_H_
22
23 #include <ncurses.h>
24 #include <panel.h>
25 #include <menu.h>
26
27 struct dialog;
28 struct dialog_section;
29
30 /* dialog submit cb. return true to close dialog, false to keep
31    it open */
32 typedef bool (*dialog_submit_cb)(struct dialog *, struct dialog_section *,
33                                  void *);
34
35 struct dialog {
36         char *title;
37         WINDOW *window;
38         WINDOW *pad;
39         PANEL *panel;
40         int x;
41         int y;
42         short color;
43         bool centered;
44         dialog_submit_cb submit;
45         void *submit_arg;
46         struct dialog_section *head_section;
47         struct dialog_section *tail_section;
48         struct dialog_section *current_section;
49 };
50
51 enum dialog_action {
52         DIALOG_IGNORE,
53         DIALOG_OK,
54         DIALOG_CANCEL
55 };
56
57 struct dialog_section_ops {
58         /* create section */
59         WERROR (*create)(struct dialog *, struct dialog_section *);
60
61         /* (optional) cleanup the section */
62         void (*destroy)(struct dialog_section *);
63
64         /* (optional) handle character input */
65         void (*on_input)(struct dialog *, struct dialog_section *, int c);
66
67         /* (optional) handle a tab character. return true if section dealt
68            with the tab internally, or false to advance focus to
69            the next dialog section. */
70         bool (*on_tab)(struct dialog *, struct dialog_section *);
71
72         /* (optional) handle a btab character. return true if section dealt
73            with the tab internally, or false to move focus to
74            the previous dialog section. */
75         bool (*on_btab)(struct dialog *, struct dialog_section *);
76
77         /* */
78         bool (*on_up)(struct dialog *, struct dialog_section *);
79
80         /* */
81         bool (*on_down)(struct dialog *, struct dialog_section *);
82
83         /* */
84         bool (*on_left)(struct dialog *, struct dialog_section *);
85
86         /* */
87         bool (*on_right)(struct dialog *, struct dialog_section *);
88
89         /* (optional) handle enter key. return DIALOG_OK to submit
90            dialog, DIALOG_CANCEL to close dialog, or DIALOG_IGNORE to
91            handle the enter internally. */
92         enum dialog_action (*on_enter)(struct dialog *,
93                                        struct dialog_section *);
94
95         /* (optional) called when this section is about to take focus. forward
96            is set to true when focus has landed here from forward traversal,
97            such as from a tab. return true to accept focus, false to pass to an
98            adjacent section. */
99         bool (*on_focus)(struct dialog *, struct dialog_section *, bool forward);
100
101         /* (optional) called when focus is leaving this section */
102         void (*on_leave_focus)(struct dialog *, struct dialog_section *);
103 };
104
105 enum section_justify {
106         SECTION_JUSTIFY_LEFT,
107         SECTION_JUSTIFY_CENTER,
108         SECTION_JUSTIFY_RIGHT,
109 };
110
111 struct dialog_section {
112         char *name;
113         int nlines;
114         int ncols;
115         WINDOW *window;
116         enum section_justify justify;
117         const struct dialog_section_ops *ops;
118         struct dialog_section *next;
119         struct dialog_section *prev;
120 };
121
122 struct dialog *dialog_new(TALLOC_CTX *ctx, short color,
123                           const char *title, int y, int x);
124
125 void dialog_section_destroy(struct dialog_section *section);
126 void dialog_section_init(struct dialog_section *section,
127                          const struct dialog_section_ops *ops,
128                          int nlines, int ncols);
129
130 void dialog_section_set_name(struct dialog_section *section, const char *name);
131 const char *dialog_section_get_name(struct dialog_section *section);
132 void dialog_section_set_justify(struct dialog_section *section,
133                                 enum section_justify justify);
134
135 void dialog_append_section(struct dialog *dia,
136                            struct dialog_section *section);
137 struct dialog_section *dialog_find_section(struct dialog *dia,
138                                            const char *name);
139
140 WERROR dialog_create(struct dialog *dia);
141 void dialog_show(struct dialog *dia);
142 void dialog_destroy(struct dialog *dia);
143 void dialog_set_submit_cb(struct dialog *dia, dialog_submit_cb cb, void *arg);
144 bool dialog_handle_input(struct dialog *dia, WERROR *err,
145                          enum dialog_action *action);
146 void dialog_modal_loop(struct dialog *dia, WERROR *err,
147                        enum dialog_action *action);
148
149 struct dialog_section *dialog_section_label_new_va(TALLOC_CTX *ctx,
150                                                    const char *msg,
151                                                    va_list ap)
152                                                    PRINTF_ATTRIBUTE(2,0);
153 struct dialog_section *dialog_section_label_new(TALLOC_CTX *ctx,
154                                                 const char *msg, ...)
155                                                 PRINTF_ATTRIBUTE(2,3);
156
157 struct dialog_section *dialog_section_hsep_new(TALLOC_CTX *ctx, int sep);
158
159
160 struct dialog_section *dialog_section_text_field_new(TALLOC_CTX *ctx,
161                                                      int height, int width);
162 const char *dialog_section_text_field_get(TALLOC_CTX *ctx,
163                                           struct dialog_section *section);
164 const char **dialog_section_text_field_get_lines(TALLOC_CTX *ctx,
165                                                  struct dialog_section *section);
166 bool dialog_section_text_field_get_int(struct dialog_section *section,
167                                        long long *out);
168 bool dialog_section_text_field_get_uint(struct dialog_section *section,
169                                         unsigned long long *out);
170 void dialog_section_text_field_set(struct dialog_section *section,
171                                    const char *s);
172 WERROR dialog_section_text_field_set_lines(TALLOC_CTX *ctx,
173                                            struct dialog_section *section,
174                                            const char **array);
175
176 struct dialog_section *dialog_section_hexedit_new(TALLOC_CTX *ctx, int height);
177 WERROR dialog_section_hexedit_set_buf(struct dialog_section *section,
178                                       const void *data, size_t size);
179 void dialog_section_hexedit_get_buf(struct dialog_section *section,
180                                     const void **data, size_t *size);
181 WERROR dialog_section_hexedit_resize(struct dialog_section *section,
182                                      size_t size);
183
184 struct button_spec {
185         const char *label;
186         enum dialog_action (*on_enter)(struct dialog *,
187                                        struct dialog_section *);
188         enum dialog_action action;
189
190         /* internal */
191         int col;
192 };
193 struct dialog_section *dialog_section_buttons_new(TALLOC_CTX *ctx,
194                                                   const struct button_spec *spec);
195
196 struct option_spec {
197         const char *label;
198         bool *state;
199
200         /* internal */
201         int col;
202         int row;
203 };
204 struct dialog_section *dialog_section_options_new(TALLOC_CTX *ctx,
205                                                   const struct option_spec *spec,
206                                                   int maxcol, bool single_select);
207
208 enum dialog_type {
209         DIA_ALERT,
210         DIA_CONFIRM
211 };
212
213 int dialog_notice(TALLOC_CTX *ctx, enum dialog_type type,
214                   const char *title, const char *msg, ...)
215                   PRINTF_ATTRIBUTE(4,5);
216
217 int dialog_input(TALLOC_CTX *ctx, const char **output, const char *title,
218                  const char *msg, ...) PRINTF_ATTRIBUTE(4,5);
219 int dialog_input_long(TALLOC_CTX *ctx, long *output,
220                       const char *title, const char *msg, ...)
221                       PRINTF_ATTRIBUTE(4,5);
222 int dialog_input_ulong(TALLOC_CTX *ctx, unsigned long *output,
223                        const char *title, const char *msg, ...)
224                        PRINTF_ATTRIBUTE(4,5);
225
226 struct registry_key;
227 struct value_item;
228
229 int dialog_edit_value(TALLOC_CTX *ctx, struct registry_key *key,
230                       uint32_t type, const struct value_item *vitem,
231                       bool force_binary, WERROR *err,
232                       const char **name);
233
234 int dialog_select_type(TALLOC_CTX *ctx, int *type);
235
236 struct regedit_search_opts;
237
238 int dialog_search_input(TALLOC_CTX *ctx, struct regedit_search_opts *opts);
239
240 #endif