2 * Samba Unix/Linux SMB client library
4 * Copyright (C) Christopher Davis 2012
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.
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.
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/>.
20 #ifndef _REGEDIT_DIALOG_H_
21 #define _REGEDIT_DIALOG_H_
28 struct dialog_section
;
30 /* dialog submit cb. return true to close dialog, false to keep
32 typedef bool (*dialog_submit_cb
)(struct dialog
*, struct dialog_section
*,
44 dialog_submit_cb submit
;
46 struct dialog_section
*head_section
;
47 struct dialog_section
*tail_section
;
48 struct dialog_section
*current_section
;
57 struct dialog_section_ops
{
59 WERROR (*create
)(struct dialog
*, struct dialog_section
*);
61 /* (optional) cleanup the section */
62 void (*destroy
)(struct dialog_section
*);
64 /* (optional) handle character input */
65 void (*on_input
)(struct dialog
*, struct dialog_section
*, int c
);
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
*);
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
*);
78 bool (*on_up
)(struct dialog
*, struct dialog_section
*);
81 bool (*on_down
)(struct dialog
*, struct dialog_section
*);
84 bool (*on_left
)(struct dialog
*, struct dialog_section
*);
87 bool (*on_right
)(struct dialog
*, struct dialog_section
*);
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
*);
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
99 bool (*on_focus
)(struct dialog
*, struct dialog_section
*, bool forward
);
101 /* (optional) called when focus is leaving this section */
102 void (*on_leave_focus
)(struct dialog
*, struct dialog_section
*);
105 enum section_justify
{
106 SECTION_JUSTIFY_LEFT
,
107 SECTION_JUSTIFY_CENTER
,
108 SECTION_JUSTIFY_RIGHT
,
111 struct dialog_section
{
116 enum section_justify justify
;
117 const struct dialog_section_ops
*ops
;
118 struct dialog_section
*next
;
119 struct dialog_section
*prev
;
122 struct dialog
*dialog_new(TALLOC_CTX
*ctx
, short color
,
123 const char *title
, int y
, int x
);
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
);
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
);
135 void dialog_append_section(struct dialog
*dia
,
136 struct dialog_section
*section
);
137 struct dialog_section
*dialog_find_section(struct dialog
*dia
,
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
);
149 struct dialog_section
*dialog_section_label_new_va(TALLOC_CTX
*ctx
,
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);
157 struct dialog_section
*dialog_section_hsep_new(TALLOC_CTX
*ctx
, int sep
);
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
,
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
,
172 WERROR
dialog_section_text_field_set_lines(TALLOC_CTX
*ctx
,
173 struct dialog_section
*section
,
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
,
186 enum dialog_action (*on_enter
)(struct dialog
*,
187 struct dialog_section
*);
188 enum dialog_action action
;
193 struct dialog_section
*dialog_section_buttons_new(TALLOC_CTX
*ctx
,
194 const struct button_spec
*spec
);
204 struct dialog_section
*dialog_section_options_new(TALLOC_CTX
*ctx
,
205 const struct option_spec
*spec
,
206 int maxcol
, bool single_select
);
213 int dialog_notice(TALLOC_CTX
*ctx
, enum dialog_type type
,
214 const char *title
, const char *msg
, ...)
215 PRINTF_ATTRIBUTE(4,5);
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);
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
,
234 int dialog_select_type(TALLOC_CTX
*ctx
, int *type
);
236 struct regedit_search_opts
;
238 int dialog_search_input(TALLOC_CTX
*ctx
, struct regedit_search_opts
*opts
);