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/>.
22 #include "regedit_dialog.h"
23 #include "regedit_valuelist.h"
24 #include "regedit_hexedit.h"
26 #include "lib/registry/registry.h"
30 static char *string_trim_n(TALLOC_CTX
*ctx
, const char *buf
, size_t n
)
34 str
= talloc_strndup(ctx
, buf
, n
);
37 trim_string(str
, " ", " ");
43 static char *string_trim(TALLOC_CTX
*ctx
, const char *buf
)
47 str
= talloc_strdup(ctx
, buf
);
50 trim_string(str
, " ", " ");
56 static int dialog_free(struct dialog
*dia
)
61 if (dia
->sub_window
) {
62 delwin(dia
->sub_window
);
65 del_panel(dia
->panel
);
68 unpost_menu(dia
->choices
);
69 free_menu(dia
->choices
);
71 if (dia
->choice_items
) {
73 for (it
= dia
->choice_items
; *it
!= NULL
; ++it
) {
81 struct dialog
*dialog_new(TALLOC_CTX
*ctx
, const char *title
, int nlines
,
82 int ncols
, int y
, int x
)
86 dia
= talloc_zero(ctx
, struct dialog
);
91 talloc_set_destructor(dia
, dialog_free
);
93 dia
->window
= newwin(nlines
, ncols
, y
, x
);
94 if (dia
->window
== NULL
) {
98 box(dia
->window
, 0, 0);
99 mvwaddstr(dia
->window
, 0, 1, title
);
101 /* body of the dialog within the box outline */
102 dia
->sub_window
= derwin(dia
->window
, nlines
- 2, ncols
- 2, 1, 1);
103 if (dia
->sub_window
== NULL
) {
107 dia
->panel
= new_panel(dia
->window
);
108 if (dia
->panel
== NULL
) {
121 static void center_dialog_above_window(int *nlines
, int *ncols
,
124 int centery
, centerx
;
131 if (*nlines
> LINES
) {
138 if (*nlines
/2 < centery
) {
139 *y
= centery
- *nlines
/ 2;
141 if (*ncols
/2 < centerx
) {
142 *x
= centerx
- *ncols
/ 2;
146 static int dialog_getch(struct dialog
*dia
)
152 if (c
== KEY_RESIZE
) {
153 int nlines
, ncols
, y
, x
;
155 getmaxyx(dia
->window
, nlines
, ncols
);
156 getbegyx(dia
->window
, y
, x
);
158 center_dialog_above_window(&nlines
, &ncols
, &y
, &x
);
160 if (nlines
+ y
> LINES
) {
161 if (nlines
> LINES
) {
167 if (ncols
+ x
> COLS
) {
175 move_panel(dia
->panel
, y
, x
);
182 struct dialog
*dialog_center_new(TALLOC_CTX
*ctx
, const char *title
,
183 int nlines
, int ncols
)
188 center_dialog_above_window(&nlines
, &ncols
, &y
, &x
);
190 dia
= dialog_new(ctx
, title
, nlines
, ncols
, y
, x
);
192 dia
->centered
= true;
198 struct dialog
*dialog_choice_new(TALLOC_CTX
*ctx
, const char *title
,
199 const char **choices
, int nlines
,
200 int ncols
, int y
, int x
)
205 dia
= dialog_new(ctx
, title
, nlines
, ncols
, y
, x
);
210 dia
->menu_window
= derwin(dia
->sub_window
, 1, ncols
- 3,
212 if (dia
->menu_window
== NULL
) {
216 for (nchoices
= 0; choices
[nchoices
] != NULL
; ++nchoices
)
218 dia
->choice_items
= talloc_zero_array(dia
, ITEM
*, nchoices
+ 1);
219 if (dia
->choice_items
== NULL
) {
222 for (i
= 0; i
< nchoices
; ++i
) {
223 char *desc
= talloc_strdup(dia
, choices
[i
]);
227 dia
->choice_items
[i
] = new_item(desc
, desc
);
228 if (dia
->choice_items
[i
] == NULL
) {
231 /* store choice index */
232 set_item_userptr(dia
->choice_items
[i
], (void*)(uintptr_t)i
);
235 dia
->choices
= new_menu(dia
->choice_items
);
236 if (dia
->choices
== NULL
) {
240 set_menu_format(dia
->choices
, 1, ncols
);
241 set_menu_win(dia
->choices
, dia
->sub_window
);
242 set_menu_sub(dia
->choices
, dia
->menu_window
);
243 menu_opts_off(dia
->choices
, O_SHOWDESC
);
244 set_menu_mark(dia
->choices
, "* ");
245 post_menu(dia
->choices
);
246 wmove(dia
->sub_window
, 0, 0);
256 struct dialog
*dialog_choice_center_new(TALLOC_CTX
*ctx
, const char *title
,
257 const char **choices
, int nlines
,
262 center_dialog_above_window(&nlines
, &ncols
, &y
, &x
);
264 dia
= dialog_choice_new(ctx
, title
, choices
, nlines
, ncols
, y
, x
);
266 dia
->centered
= true;
272 static bool current_item_is_first(MENU
*menu
)
274 const ITEM
*it
= current_item(menu
);
276 return item_index(it
) == 0;
279 static bool current_item_is_last(MENU
*menu
)
281 const ITEM
*it
= current_item(menu
);
283 return item_index(it
) == item_count(menu
) - 1;
286 static int handle_menu_input(MENU
*menu
, int c
)
292 if (current_item_is_first(menu
)) {
293 menu_driver(menu
, REQ_LAST_ITEM
);
295 menu_driver(menu
, REQ_LEFT_ITEM
);
299 menu_driver(menu
, REQ_LEFT_ITEM
);
302 if (current_item_is_last(menu
)) {
303 menu_driver(menu
, REQ_FIRST_ITEM
);
306 menu_driver(menu
, REQ_RIGHT_ITEM
);
309 menu_driver(menu
, REQ_RIGHT_ITEM
);
313 item
= current_item(menu
);
314 return (int)(uintptr_t)item_userptr(item
);
320 static void handle_form_input(FORM
*frm
, int c
)
324 form_driver(frm
, REQ_NEW_LINE
);
327 form_driver(frm
, REQ_UP_CHAR
);
330 form_driver(frm
, REQ_DOWN_CHAR
);
334 form_driver(frm
, REQ_DEL_PREV
);
337 form_driver(frm
, REQ_LEFT_CHAR
);
340 form_driver(frm
, REQ_RIGHT_CHAR
);
348 static int modal_loop(struct dialog
*dia
)
356 while (selection
== -1) {
357 c
= dialog_getch(dia
);
358 selection
= handle_menu_input(dia
->choices
, c
);
368 static struct dialog
*dialog_msg_new(TALLOC_CTX
*ctx
, const char *title
,
369 const char **choices
, int nlines
,
370 const char *msg
, va_list ap
)
377 str
= talloc_vasprintf(ctx
, msg
, ap
);
382 width
= strlen(str
) + 2;
383 if (width
< MIN_WIDTH
) {
386 dia
= dialog_choice_center_new(ctx
, title
, choices
, nlines
, width
);
391 waddstr(dia
->sub_window
, str
);
397 int dialog_input(TALLOC_CTX
*ctx
, char **output
, const char *title
,
398 const char *msg
, ...)
402 const char *choices
[] = {
407 FIELD
*field
[2] = {0};
412 bool input_section
= true;
415 dia
= dialog_msg_new(ctx
, title
, choices
, 7, msg
, ap
);
421 getmaxyx(dia
->sub_window
, y
, x
);
422 input_win
= derwin(dia
->sub_window
, 1, x
- 2, 2, 1);
423 if (input_win
== NULL
) {
426 field
[0] = new_field(1, x
- 2, 0, 0, 0, 0);
427 if (field
[0] == NULL
) {
431 field_opts_off(field
[0], O_BLANK
| O_AUTOSKIP
| O_STATIC
);
432 set_field_back(field
[0], A_REVERSE
);
434 input
= new_form(field
);
435 form_opts_off(input
, O_NL_OVERLOAD
| O_BS_OVERLOAD
);
436 set_form_win(input
, dia
->sub_window
);
437 set_form_sub(input
, input_win
);
438 set_current_field(input
, field
[0]);
446 int c
= dialog_getch(dia
);
448 if (c
== '\t' || c
== KEY_BTAB
) {
450 int valid
= form_driver(input
, REQ_VALIDATION
);
452 input_section
= false;
454 menu_driver(dia
->choices
,
457 menu_driver(dia
->choices
,
460 pos_menu_cursor(dia
->choices
);
464 current_item_is_last(dia
->choices
)) ||
466 current_item_is_first(dia
->choices
))) {
467 input_section
= true;
468 set_current_field(input
, field
[0]);
469 pos_form_cursor(input
);
471 handle_menu_input(dia
->choices
, c
);
474 } else if (input_section
) {
475 handle_form_input(input
, c
);
477 rv
= handle_menu_input(dia
->choices
, c
);
478 if (rv
== DIALOG_OK
) {
479 const char *buf
= field_buffer(field
[0], 0);
480 *output
= string_trim(ctx
, buf
);
493 free_field(field
[0]);
503 int dialog_notice(TALLOC_CTX
*ctx
, enum dialog_type type
,
504 const char *title
, const char *msg
, ...)
508 const char *choices
[] = {
514 if (type
== DIA_ALERT
) {
519 dia
= dialog_msg_new(ctx
, title
, choices
, 5, msg
, ap
);
525 return modal_loop(dia
);
528 #define EDIT_WIDTH 50
529 #define EDIT_INTERNAL_WIDTH (EDIT_WIDTH - 2)
530 #define EDIT_INPUT_WIDTH (EDIT_INTERNAL_WIDTH - 2)
532 #define EDIT_NAME_LABEL_Y 0
533 #define EDIT_NAME_LABEL_X 0
534 #define EDIT_NAME_LABEL_WIDTH EDIT_INTERNAL_WIDTH
535 #define EDIT_NAME_LABEL_HEIGHT 1
536 #define EDIT_NAME_INPUT_Y 1
537 #define EDIT_NAME_INPUT_X 1
538 #define EDIT_NAME_INPUT_WIDTH EDIT_INPUT_WIDTH
539 #define EDIT_NAME_INPUT_HEIGHT 1
541 #define EDIT_DATA_LABEL_Y 3
542 #define EDIT_DATA_LABEL_X 0
543 #define EDIT_DATA_LABEL_WIDTH EDIT_INTERNAL_WIDTH
544 #define EDIT_DATA_LABEL_HEIGHT 1
545 #define EDIT_DATA_INPUT_Y 4
546 #define EDIT_DATA_INPUT_X 1
547 #define EDIT_DATA_INPUT_WIDTH EDIT_INPUT_WIDTH
548 #define EDIT_DATA_HEIGHT_ONELINE 1
549 #define EDIT_DATA_HEIGHT_MULTILINE 5
550 #define EDIT_DATA_HEIGHT_BUF 10
552 #define EDIT_FORM_WIN_Y 0
553 #define EDIT_FORM_WIN_X 0
554 #define EDIT_FORM_WIN_HEIGHT_ONELINE \
555 (EDIT_NAME_LABEL_HEIGHT + EDIT_NAME_INPUT_HEIGHT + 1 + \
556 EDIT_DATA_LABEL_HEIGHT + EDIT_DATA_HEIGHT_ONELINE)
558 #define EDIT_FORM_WIN_HEIGHT_MULTILINE \
559 (EDIT_NAME_LABEL_HEIGHT + EDIT_NAME_INPUT_HEIGHT + 1 + \
560 EDIT_DATA_LABEL_HEIGHT + EDIT_DATA_HEIGHT_MULTILINE)
562 #define EDIT_FORM_WIN_HEIGHT_BUF \
563 (EDIT_NAME_LABEL_HEIGHT + EDIT_NAME_INPUT_HEIGHT + 1 + \
564 EDIT_DATA_LABEL_HEIGHT)
566 #define EDIT_FORM_WIN_WIDTH EDIT_INTERNAL_WIDTH
569 #define EDIT_HEIGHT_ONELINE (EDIT_FORM_WIN_HEIGHT_ONELINE + EDIT_PAD)
571 #define EDIT_HEIGHT_MULTILINE (EDIT_FORM_WIN_HEIGHT_MULTILINE + EDIT_PAD)
573 #define EDIT_HEIGHT_BUF \
574 (EDIT_FORM_WIN_HEIGHT_BUF + EDIT_DATA_HEIGHT_BUF + EDIT_PAD)
580 #define DIALOG_RESIZE 2
592 FIELD
*field
[MAX_FIELDS
];
594 enum input_section section
;
599 static int edit_dialog_free(struct edit_dialog
*edit
)
604 unpost_form(edit
->input
);
605 free_form(edit
->input
);
607 for (f
= edit
->field
; *f
; ++f
) {
610 delwin(edit
->input_win
);
615 static WERROR
fill_value_buffer(struct edit_dialog
*edit
,
616 const struct value_item
*vitem
)
620 switch (vitem
->type
) {
623 if (vitem
->data
.length
>= 4) {
624 v
= IVAL(vitem
->data
.data
, 0);
626 tmp
= talloc_asprintf(edit
, "0x%x", v
);
630 set_field_buffer(edit
->field
[FLD_DATA
], 0, tmp
);
635 case REG_EXPAND_SZ
: {
638 if (!pull_reg_sz(edit
, &vitem
->data
, &s
)) {
641 set_field_buffer(edit
->field
[FLD_DATA
], 0, s
);
648 if (!pull_reg_multi_sz(edit
, &vitem
->data
, &a
)) {
651 for (p
= a
; *p
!= NULL
; ++p
) {
653 buf
= talloc_asprintf(edit
, "%s\n", *p
);
655 buf
= talloc_asprintf_append(buf
, "%s\n", *p
);
661 set_field_buffer(edit
->field
[FLD_DATA
], 0, buf
);
665 /* initialized upon dialog creation */
672 static bool value_exists(TALLOC_CTX
*ctx
, const struct registry_key
*key
,
679 rv
= reg_key_get_value_by_name(ctx
, key
, name
, &type
, &blob
);
681 return W_ERROR_IS_OK(rv
);
684 static WERROR
set_value(struct edit_dialog
*edit
, struct registry_key
*key
,
685 uint32_t type
, bool new_value
)
689 char *name
= string_trim(edit
, field_buffer(edit
->field
[FLD_NAME
], 0));
691 if (!new_value
&& !edit
->buf
&& !field_status(edit
->field
[FLD_DATA
])) {
694 if (new_value
&& value_exists(edit
, key
, name
)) {
695 return WERR_FILE_EXISTS
;
698 switch (edit
->mode
) {
702 const char *buf
= field_buffer(edit
->field
[FLD_DATA
], 0);
704 if (buf
[0] == '0' && tolower(buf
[1]) == 'x') {
708 val
= strtoul(buf
, NULL
, base
);
709 blob
= data_blob_talloc(edit
, NULL
, sizeof(val
));
710 SIVAL(blob
.data
, 0, val
);
715 case REG_EXPAND_SZ
: {
716 const char *buf
= field_buffer(edit
->field
[FLD_DATA
], 0);
717 char *str
= string_trim(edit
, buf
);
719 if (!str
|| !push_reg_sz(edit
, &blob
, str
)) {
728 const char *buf
= field_buffer(edit
->field
[FLD_DATA
], 0);
730 dynamic_field_info(edit
->field
[FLD_DATA
], &rows
, &cols
, &max
);
732 arr
= talloc_zero_array(edit
, const char *, rows
+ 1);
736 for (i
= 0; *buf
; ++i
, buf
+= cols
) {
737 SMB_ASSERT(i
< rows
);
738 arr
[i
] = string_trim_n(edit
, buf
, cols
);
740 if (!push_reg_multi_sz(edit
, &blob
, arr
)) {
746 blob
= data_blob_talloc(edit
, NULL
, edit
->buf
->len
);
747 memcpy(blob
.data
, edit
->buf
->data
, edit
->buf
->len
);
751 rv
= reg_val_set(key
, name
, type
, blob
);
756 static void section_down(struct edit_dialog
*edit
)
758 switch (edit
->section
) {
760 if (form_driver(edit
->input
, REQ_VALIDATION
) == E_OK
) {
761 edit
->section
= IN_DATA
;
763 hexedit_set_cursor(edit
->buf
);
765 set_current_field(edit
->input
,
766 edit
->field
[FLD_DATA
]);
767 pos_form_cursor(edit
->input
);
773 form_driver(edit
->input
, REQ_VALIDATION
) == E_OK
) {
774 edit
->section
= IN_MENU
;
775 menu_driver(edit
->dia
->choices
, REQ_FIRST_ITEM
);
776 pos_menu_cursor(edit
->dia
->choices
);
780 if (current_item_is_last(edit
->dia
->choices
)) {
781 edit
->section
= IN_NAME
;
782 set_current_field(edit
->input
, edit
->field
[FLD_NAME
]);
783 pos_form_cursor(edit
->input
);
785 menu_driver(edit
->dia
->choices
, REQ_RIGHT_ITEM
);
791 static void section_up(struct edit_dialog
*edit
)
793 switch (edit
->section
) {
795 if (form_driver(edit
->input
, REQ_VALIDATION
) == E_OK
) {
796 edit
->section
= IN_MENU
;
797 menu_driver(edit
->dia
->choices
, REQ_LAST_ITEM
);
798 pos_menu_cursor(edit
->dia
->choices
);
803 form_driver(edit
->input
, REQ_VALIDATION
) == E_OK
) {
804 edit
->section
= IN_NAME
;
805 set_current_field(edit
->input
, edit
->field
[FLD_NAME
]);
806 pos_form_cursor(edit
->input
);
810 if (current_item_is_first(edit
->dia
->choices
)) {
811 edit
->section
= IN_DATA
;
813 hexedit_set_cursor(edit
->buf
);
815 set_current_field(edit
->input
,
816 edit
->field
[FLD_DATA
]);
817 pos_form_cursor(edit
->input
);
820 menu_driver(edit
->dia
->choices
, REQ_LEFT_ITEM
);
826 static void handle_hexedit_input(struct hexedit
*buf
, int c
)
830 hexedit_driver(buf
, HE_CURSOR_UP
);
833 hexedit_driver(buf
, HE_CURSOR_DOWN
);
836 hexedit_driver(buf
, HE_CURSOR_LEFT
);
839 hexedit_driver(buf
, HE_CURSOR_RIGHT
);
842 hexedit_driver(buf
, c
);
846 hexedit_set_cursor(buf
);
849 static WERROR
edit_init_dialog(struct edit_dialog
*edit
, uint32_t type
)
854 const char *choices
[] = {
861 switch (edit
->mode
) {
863 diaheight
= EDIT_HEIGHT_MULTILINE
;
864 winheight
= EDIT_FORM_WIN_HEIGHT_MULTILINE
;
868 diaheight
= EDIT_HEIGHT_BUF
;
869 winheight
= EDIT_FORM_WIN_HEIGHT_BUF
;
872 diaheight
= EDIT_HEIGHT_ONELINE
;
873 winheight
= EDIT_FORM_WIN_HEIGHT_ONELINE
;
878 title
= talloc_asprintf(edit
, "Edit %s value", str_regtype(type
));
882 edit
->dia
= dialog_choice_center_new(edit
, title
, choices
, diaheight
,
885 if (edit
->dia
== NULL
) {
888 edit
->input_win
= derwin(edit
->dia
->sub_window
, winheight
,
890 EDIT_FORM_WIN_Y
, EDIT_FORM_WIN_X
);
891 if (edit
->input_win
== NULL
) {
898 static WERROR
edit_init_form(struct edit_dialog
*edit
,
899 const struct value_item
*vitem
)
902 edit
->field
[0] = new_field(EDIT_NAME_LABEL_HEIGHT
,
903 EDIT_NAME_LABEL_WIDTH
,
905 EDIT_NAME_LABEL_X
, 0, 0);
906 if (edit
->field
[0] == NULL
) {
909 set_field_buffer(edit
->field
[0], 0, "Name");
910 field_opts_off(edit
->field
[0], O_EDIT
);
912 edit
->field
[FLD_NAME
] = new_field(EDIT_NAME_INPUT_HEIGHT
,
913 EDIT_NAME_INPUT_WIDTH
,
915 EDIT_NAME_INPUT_X
, 0, 0);
916 if (edit
->field
[FLD_NAME
] == NULL
) {
920 edit
->field
[2] = new_field(EDIT_DATA_LABEL_HEIGHT
,
921 EDIT_DATA_LABEL_WIDTH
,
923 EDIT_DATA_LABEL_X
, 0, 0);
924 if (edit
->field
[2] == NULL
) {
927 set_field_buffer(edit
->field
[2], 0, "Data");
928 field_opts_off(edit
->field
[2], O_EDIT
);
930 if (edit
->mode
== REG_BINARY
) {
932 const void *buf
= NULL
;
935 len
= vitem
->data
.length
;
936 buf
= vitem
->data
.data
;
938 edit
->buf
= hexedit_new(edit
, edit
->dia
->sub_window
,
939 EDIT_DATA_HEIGHT_BUF
,
943 if (edit
->buf
== NULL
) {
946 hexedit_refresh(edit
->buf
);
947 hexedit_set_cursor(edit
->buf
);
949 int val_rows
= EDIT_DATA_HEIGHT_ONELINE
;
951 if (edit
->mode
== REG_MULTI_SZ
) {
952 val_rows
= EDIT_DATA_HEIGHT_MULTILINE
;
954 edit
->field
[FLD_DATA
] = new_field(val_rows
,
955 EDIT_DATA_INPUT_WIDTH
,
957 EDIT_DATA_INPUT_X
, 0, 0);
958 if (edit
->field
[FLD_DATA
] == NULL
) {
963 set_field_back(edit
->field
[FLD_NAME
], A_REVERSE
);
964 field_opts_off(edit
->field
[FLD_NAME
], O_BLANK
| O_AUTOSKIP
| O_STATIC
);
965 if (edit
->field
[FLD_DATA
]) {
966 set_field_back(edit
->field
[FLD_DATA
], A_REVERSE
);
967 field_opts_off(edit
->field
[FLD_DATA
],
968 O_BLANK
| O_AUTOSKIP
| O_STATIC
| O_WRAP
);
969 if (edit
->mode
== REG_DWORD
) {
970 set_field_type(edit
->field
[FLD_DATA
], TYPE_REGEXP
,
971 "^ *([0-9]+|0[xX][0-9a-fA-F]+) *$");
976 set_field_buffer(edit
->field
[FLD_NAME
], 0, vitem
->value_name
);
977 field_opts_off(edit
->field
[FLD_NAME
], O_EDIT
);
978 fill_value_buffer(edit
, vitem
);
981 edit
->input
= new_form(edit
->field
);
982 if (edit
->input
== NULL
) {
985 form_opts_off(edit
->input
, O_NL_OVERLOAD
| O_BS_OVERLOAD
);
987 set_form_win(edit
->input
, edit
->dia
->sub_window
);
988 set_form_sub(edit
->input
, edit
->input_win
);
989 set_current_field(edit
->input
, edit
->field
[FLD_NAME
]);
990 post_form(edit
->input
);
995 static WERROR
handle_editor_input(struct edit_dialog
*edit
,
996 struct registry_key
*key
,
998 const struct value_item
*vitem
, int c
)
1000 WERROR rv
= WERR_OK
;
1003 if (edit
->section
== IN_NAME
) {
1004 handle_form_input(edit
->input
, c
);
1005 } else if (edit
->section
== IN_DATA
) {
1007 handle_hexedit_input(edit
->buf
, c
);
1009 handle_form_input(edit
->input
, c
);
1012 selection
= handle_menu_input(edit
->dia
->choices
, c
);
1013 if (selection
== DIALOG_OK
) {
1014 rv
= set_value(edit
, key
, type
, vitem
== NULL
);
1015 if (W_ERROR_EQUAL(rv
, WERR_FILE_EXISTS
)) {
1016 dialog_notice(edit
, DIA_ALERT
,
1018 "Value name already exists.");
1021 edit
->closing
= true;
1023 } else if (selection
== DIALOG_RESIZE
) {
1027 dialog_input(edit
, &n
, "Resize buffer",
1030 newlen
= strtoul(n
, NULL
, 10);
1031 edit
->section
= IN_DATA
;
1032 hexedit_resize_buffer(edit
->buf
, newlen
);
1033 hexedit_refresh(edit
->buf
);
1034 hexedit_set_cursor(edit
->buf
);
1037 } else if (selection
== DIALOG_CANCEL
) {
1038 edit
->closing
= true;
1045 WERROR
dialog_edit_value(TALLOC_CTX
*ctx
, struct registry_key
*key
,
1046 uint32_t type
, const struct value_item
*vitem
,
1049 struct edit_dialog
*edit
;
1050 WERROR rv
= WERR_NOMEM
;
1052 edit
= talloc_zero(ctx
, struct edit_dialog
);
1056 talloc_set_destructor(edit
, edit_dialog_free
);
1059 if (force_binary
|| (vitem
&& vitem
->unprintable
)) {
1060 edit
->mode
= REG_BINARY
;
1063 rv
= edit_init_dialog(edit
, type
);
1064 if (!W_ERROR_IS_OK(rv
)) {
1067 rv
= edit_init_form(edit
, vitem
);
1068 if (!W_ERROR_IS_OK(rv
)) {
1075 edit
->section
= IN_NAME
;
1076 edit
->closing
= false;
1079 int c
= dialog_getch(edit
->dia
);
1083 } else if (c
== KEY_BTAB
) {
1086 rv
= handle_editor_input(edit
, key
, type
, vitem
, c
);
1091 } while (!edit
->closing
);
1099 int dialog_select_type(TALLOC_CTX
*ctx
, int *type
)
1102 const char *choices
[] = {
1107 const char *reg_types
[] = {
1114 #define NTYPES (sizeof(reg_types) / sizeof(const char*))
1121 dia
= dialog_choice_center_new(ctx
, "New Value", choices
, 10, 20);
1126 mvwprintw(dia
->sub_window
, 0, 0, "Choose type:");
1127 type_win
= derwin(dia
->sub_window
, 6, 18, 1, 0);
1128 if (type_win
== NULL
) {
1132 item
= talloc_zero_array(dia
, ITEM
*, NTYPES
+ 1);
1137 for (i
= 0; i
< NTYPES
; ++i
) {
1138 int t
= regtype_by_string(reg_types
[i
]);
1140 item
[i
] = new_item(reg_types
[i
], reg_types
[i
]);
1141 if (item
[i
] == NULL
) {
1144 set_item_userptr(item
[i
], (void*)(uintptr_t)t
);
1147 list
= new_menu(item
);
1152 set_menu_format(list
, 7, 1);
1153 set_menu_win(list
, dia
->sub_window
);
1154 set_menu_sub(list
, type_win
);
1155 menu_opts_off(list
, O_SHOWDESC
);
1156 set_menu_mark(list
, "* ");
1164 int c
= dialog_getch(dia
);
1168 menu_driver(list
, REQ_UP_ITEM
);
1171 menu_driver(list
, REQ_DOWN_ITEM
);
1174 menu_driver(dia
->choices
, REQ_LEFT_ITEM
);
1177 menu_driver(dia
->choices
, REQ_RIGHT_ITEM
);
1181 it
= current_item(list
);
1182 *type
= (int)(uintptr_t)item_userptr(it
);
1183 it
= current_item(dia
->choices
);
1184 sel
= (int)(uintptr_t)item_userptr(it
);
1199 for (it
= item
; *it
; ++it
) {