char * tree_box (const char *current_dir) { WTree *mytree; WDialog *dlg; Widget *wd; char *val = NULL; WButtonBar *bar; (void) current_dir; /* Create the components */ dlg = dlg_create (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors, tree_callback, NULL, "[Directory Tree]", _("Directory tree"), DLG_CENTER); wd = WIDGET (dlg); mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE); add_widget_autopos (dlg, mytree, WPOS_KEEP_ALL, NULL); add_widget_autopos (dlg, hline_new (wd->lines - 4, 1, -1), WPOS_KEEP_BOTTOM, NULL); bar = buttonbar_new (TRUE); add_widget (dlg, bar); /* restore ButtonBar coordinates after add_widget() */ WIDGET (bar)->x = 0; WIDGET (bar)->y = LINES - 1; if (dlg_run (dlg) == B_ENTER) { const vfs_path_t *selected_name; selected_name = tree_selected_name (mytree); val = g_strdup (vfs_path_as_str (selected_name)); } dlg_destroy (dlg); return val; }
int editcmd_dialog_raw_key_query (const char *heading, const char *query, gboolean cancel) { int w, wq; int y = 2; WDialog *raw_dlg; w = str_term_width1 (heading) + 6; wq = str_term_width1 (query); w = MAX (w, wq + 3 * 2 + 1 + 2); raw_dlg = dlg_create (TRUE, 0, 0, cancel ? 7 : 5, w, WPOS_CENTER | WPOS_TRYUP, FALSE, dialog_colors, editcmd_dialog_raw_key_query_cb, NULL, NULL, heading); widget_want_tab (WIDGET (raw_dlg), TRUE); add_widget (raw_dlg, label_new (y, 3, query)); add_widget (raw_dlg, input_new (y++, 3 + wq + 1, input_colors, w - (6 + wq + 1), "", 0, INPUT_COMPLETE_NONE)); if (cancel) { add_widget (raw_dlg, hline_new (y++, -1, -1)); /* Button w/o hotkey to allow use any key as raw or macro one */ add_widget_autopos (raw_dlg, button_new (y, 1, B_CANCEL, NORMAL_BUTTON, _("Cancel"), NULL), WPOS_KEEP_TOP | WPOS_CENTER_HORZ, NULL); } w = dlg_run (raw_dlg); dlg_destroy (raw_dlg); return (cancel && (w == ESC_CHAR || w == B_CANCEL)) ? 0 : w; }
unsigned long add_widget_before (WDialog * h, void *w, void *before) { return add_widget_autopos (h, w, WPOS_KEEP_DEFAULT, before); }
unsigned long add_widget (WDialog * h, void *w) { return add_widget_autopos (h, w, WPOS_KEEP_DEFAULT, h->current != NULL ? h->current->data : NULL); }
void file_op_context_create_ui (file_op_context_t * ctx, gboolean with_eta, filegui_dialog_type_t dialog_type) { file_op_context_ui_t *ui; int buttons_width; int dlg_width = 58, dlg_height = 17; int y = 2, x = 3; if (ctx == NULL || ctx->ui != NULL) return; #ifdef ENABLE_NLS if (progress_buttons[0].len == -1) { size_t i; for (i = 0; i < G_N_ELEMENTS (progress_buttons); i++) progress_buttons[i].text = _(progress_buttons[i].text); } #endif ctx->dialog_type = dialog_type; ctx->recursive_result = RECURSIVE_YES; ctx->ui = g_new0 (file_op_context_ui_t, 1); ui = ctx->ui; ui->replace_result = REPLACE_YES; ui->op_dlg = dlg_create (TRUE, 0, 0, dlg_height, dlg_width, dialog_colors, NULL, NULL, NULL, op_names[ctx->operation], DLG_CENTER); if (dialog_type != FILEGUI_DIALOG_DELETE_ITEM) { ui->showing_eta = with_eta && ctx->progress_totals_computed; ui->showing_bps = with_eta; ui->src_file_label = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->src_file_label); ui->src_file = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->src_file); ui->tgt_file_label = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->tgt_file_label); ui->tgt_file = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->tgt_file); ui->progress_file_gauge = gauge_new (y++, x + 3, dlg_width - (x + 3) * 2, FALSE, 100, 0); if (!classic_progressbar && (current_panel == right_panel)) ui->progress_file_gauge->from_left_to_right = FALSE; add_widget_autopos (ui->op_dlg, ui->progress_file_gauge, WPOS_KEEP_TOP | WPOS_KEEP_HORZ, NULL); ui->progress_file_label = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->progress_file_label); if (verbose && dialog_type == FILEGUI_DIALOG_MULTI_ITEM) { ui->total_bytes_label = hline_new (y++, -1, -1); add_widget (ui->op_dlg, ui->total_bytes_label); if (ctx->progress_totals_computed) { ui->progress_total_gauge = gauge_new (y++, x + 3, dlg_width - (x + 3) * 2, FALSE, 100, 0); if (!classic_progressbar && (current_panel == right_panel)) ui->progress_total_gauge->from_left_to_right = FALSE; add_widget_autopos (ui->op_dlg, ui->progress_total_gauge, WPOS_KEEP_TOP | WPOS_KEEP_HORZ, NULL); } ui->total_files_processed_label = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->total_files_processed_label); ui->time_label = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->time_label); } } else { ui->src_file = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->src_file); ui->total_files_processed_label = label_new (y++, x, ""); add_widget (ui->op_dlg, ui->total_files_processed_label); } add_widget (ui->op_dlg, hline_new (y++, -1, -1)); progress_buttons[0].w = WIDGET (button_new (y, 0, progress_buttons[0].action, progress_buttons[0].flags, progress_buttons[0].text, progress_button_callback)); if (progress_buttons[0].len == -1) progress_buttons[0].len = button_get_len (BUTTON (progress_buttons[0].w)); progress_buttons[1].w = WIDGET (button_new (y, 0, progress_buttons[1].action, progress_buttons[1].flags, progress_buttons[1].text, progress_button_callback)); if (progress_buttons[1].len == -1) progress_buttons[1].len = button_get_len (BUTTON (progress_buttons[1].w)); if (progress_buttons[2].len == -1) { /* create and destroy button to get it length */ progress_buttons[2].w = WIDGET (button_new (y, 0, progress_buttons[2].action, progress_buttons[2].flags, progress_buttons[2].text, progress_button_callback)); progress_buttons[2].len = button_get_len (BUTTON (progress_buttons[2].w)); send_message (progress_buttons[2].w, NULL, MSG_DESTROY, 0, NULL); g_free (progress_buttons[2].w); } progress_buttons[2].w = progress_buttons[1].w; progress_buttons[3].w = WIDGET (button_new (y, 0, progress_buttons[3].action, progress_buttons[3].flags, progress_buttons[3].text, NULL)); if (progress_buttons[3].len == -1) progress_buttons[3].len = button_get_len (BUTTON (progress_buttons[3].w)); add_widget (ui->op_dlg, progress_buttons[0].w); add_widget (ui->op_dlg, progress_buttons[1].w); add_widget (ui->op_dlg, progress_buttons[3].w); buttons_width = 2 + progress_buttons[0].len + max (progress_buttons[1].len, progress_buttons[2].len) + progress_buttons[3].len; /* adjust dialog sizes */ dlg_set_size (ui->op_dlg, y + 3, max (COLS * 2 / 3, buttons_width + 6)); place_progress_buttons (ui->op_dlg, FALSE); dlg_select_widget (progress_buttons[0].w); /* We will manage the dialog without any help, that's why we have to call dlg_init */ dlg_init (ui->op_dlg); }
int quick_dialog_skip (quick_dialog_t * quick_dlg, int nskip) { int len; int blen = 0; int x, y; /* current positions */ int y1 = 0; /* bottom of 1st column in case of two columns */ int y2 = -1; /* start of two columns */ int width1 = 0; /* width of single column */ int width2 = 0; /* width of each of two columns */ gboolean have_groupbox = FALSE; gboolean two_columns = FALSE; gboolean put_buttons = FALSE; /* x position of 1st column is 3 */ const int x1 = 3; /* x position of 2nd column is 4 and it will be fixed later, after creation of all widgets */ int x2 = 4; GArray *widgets; size_t i; quick_widget_t *quick_widget; WGroupbox *g = NULL; WDialog *dd; int return_val; len = str_term_width1 (I18N (quick_dlg->title)) + 6; quick_dlg->cols = max (quick_dlg->cols, len); y = 1; x = x1; /* create widgets */ widgets = g_array_sized_new (FALSE, FALSE, sizeof (quick_widget_item_t), 8); for (quick_widget = quick_dlg->widgets; quick_widget->widget_type != quick_end; quick_widget++) { quick_widget_item_t item = { NULL, quick_widget }; int width = 0; switch (quick_widget->widget_type) { case quick_checkbox: item.widget = WIDGET (check_new (++y, x, *quick_widget->u.checkbox.state, I18N (quick_widget->u.checkbox.text))); g_array_append_val (widgets, item); width = item.widget->cols; if (g != NULL) width += 2; if (two_columns) width2 = max (width2, width); else width1 = max (width1, width); break; case quick_button: /* single button */ item.widget = WIDGET (button_new (++y, x, quick_widget->u.button.action, quick_widget->u.button.action == B_ENTER ? DEFPUSH_BUTTON : NORMAL_BUTTON, I18N (quick_widget->u.button.text), quick_widget->u.button.callback)); g_array_append_val (widgets, item); width = item.widget->cols; if (g != NULL) width += 2; if (two_columns) width2 = max (width2, width); else width1 = max (width1, width); break; case quick_input: *quick_widget->u.input.result = NULL; y++; if (quick_widget->u.input.label_location != input_label_none) quick_create_labeled_input (widgets, &y, x, quick_widget, &width); else { item.widget = WIDGET (quick_create_input (y, x, quick_widget)); g_array_append_val (widgets, item); width = item.widget->cols; } if (g != NULL) width += 2; if (two_columns) width2 = max (width2, width); else width1 = max (width1, width); break; case quick_label: item.widget = WIDGET (label_new (++y, x, I18N (quick_widget->u.label.text))); g_array_append_val (widgets, item); y += item.widget->lines - 1; width = item.widget->cols; if (g != NULL) width += 2; if (two_columns) width2 = max (width2, width); else width1 = max (width1, width); break; case quick_radio: { WRadio *r; char **items = NULL; /* create the copy of radio_items to avoid mwmory leak */ items = g_new (char *, quick_widget->u.radio.count + 1); for (i = 0; i < (size_t) quick_widget->u.radio.count; i++) items[i] = g_strdup (_(quick_widget->u.radio.items[i])); items[i] = NULL; r = radio_new (++y, x, quick_widget->u.radio.count, (const char **) items); r->pos = r->sel = *quick_widget->u.radio.value; g_strfreev (items); item.widget = WIDGET (r); g_array_append_val (widgets, item); y += item.widget->lines - 1; width = item.widget->cols; if (g != NULL) width += 2; if (two_columns) width2 = max (width2, width); else width1 = max (width1, width); } break; case quick_start_groupbox: I18N (quick_widget->u.groupbox.title); len = str_term_width1 (quick_widget->u.groupbox.title); g = groupbox_new (++y, x, 1, len + 4, quick_widget->u.groupbox.title); item.widget = WIDGET (g); g_array_append_val (widgets, item); have_groupbox = TRUE; break; case quick_stop_groupbox: if (g != NULL) { Widget *w = WIDGET (g); y++; w->lines = y + 1 - w->y; g = NULL; g_array_append_val (widgets, item); } break; case quick_separator: y++; if (quick_widget->u.separator.line) { item.widget = WIDGET (hline_new (y, x, 1)); g_array_append_val (widgets, item); } break; case quick_start_columns: y2 = y; g_array_append_val (widgets, item); two_columns = TRUE; break; case quick_next_column: x = x2; y1 = y; y = y2; break; case quick_stop_columns: x = x1; y = max (y1, y); g_array_append_val (widgets, item); two_columns = FALSE; break; case quick_buttons: /* start put several buttons in bottom line */ if (quick_widget->u.separator.space) { y++; if (quick_widget->u.separator.line) item.widget = WIDGET (hline_new (y, 1, -1)); } g_array_append_val (widgets, item); /* several buttons in bottom line */ y++; quick_widget++; for (; quick_widget->widget_type == quick_button; quick_widget++) { item.widget = WIDGET (button_new (y, x++, quick_widget->u.button.action, quick_widget->u.button.action == B_ENTER ? DEFPUSH_BUTTON : NORMAL_BUTTON, I18N (quick_widget->u.button.text), quick_widget->u.button.callback)); item.quick_widget = quick_widget; g_array_append_val (widgets, item); blen += item.widget->cols + 1; } /* stop dialog build here */ blen--; quick_widget->widget_type = quick_end; quick_widget--; break; default: break; } } /* adjust dialog width */ quick_dlg->cols = max (quick_dlg->cols, blen + 6); if (have_groupbox) { if (width1 != 0) width1 += 2; if (width2 != 0) width2 += 2; } if (width2 == 0) len = width1 + 6; else { len = width2 * 2 + 7; if (width1 != 0) len = max (len, width1 + 6); } quick_dlg->cols = max (quick_dlg->cols, len); width1 = quick_dlg->cols - 6; width2 = (quick_dlg->cols - 7) / 2; if (quick_dlg->x == -1 || quick_dlg->y == -1) dd = create_dlg (TRUE, 0, 0, y + 3, quick_dlg->cols, dialog_colors, quick_dlg->callback, quick_dlg->mouse, quick_dlg->help, quick_dlg->title, DLG_CENTER | DLG_TRYUP); else dd = create_dlg (TRUE, quick_dlg->y, quick_dlg->x, y + 3, quick_dlg->cols, dialog_colors, quick_dlg->callback, quick_dlg->mouse, quick_dlg->help, quick_dlg->title, DLG_NONE); /* add widgets into the dialog */ x2 = x1 + width2 + 1; g = NULL; two_columns = FALSE; x = (WIDGET (dd)->cols - blen) / 2; for (i = 0; i < widgets->len; i++) { quick_widget_item_t *item; int column_width; item = &g_array_index (widgets, quick_widget_item_t, i); column_width = two_columns ? width2 : width1; /* adjust widget width and x position */ switch (item->quick_widget->widget_type) { case quick_label: { quick_widget_t *input = item->quick_widget->u.label.input; if (input != NULL && input->u.input.label_location == input_label_right) { /* location of this label will be adjusted later */ break; } } /* fall through */ case quick_checkbox: case quick_radio: if (item->widget->x != x1) item->widget->x = x2; if (g != NULL) item->widget->x += 2; break; case quick_button: if (!put_buttons) { if (item->widget->x != x1) item->widget->x = x2; if (g != NULL) item->widget->x += 2; } else { item->widget->x = x; x += item->widget->cols + 1; } break; case quick_input: { Widget *label = WIDGET (INPUT (item->widget)->label); int width = column_width; if (g != NULL) width -= 4; switch (item->quick_widget->u.input.label_location) { case input_label_left: /* label was adjusted before; adjust input line */ item->widget->x = label->x + label->cols + 1 - WIDGET (label->owner)->x; item->widget->cols = width - label->cols - 1; break; case input_label_right: label->x = item->widget->x + item->widget->cols + 1 - WIDGET (item->widget->owner)->x; item->widget->cols = width - label->cols - 1; break; default: if (item->widget->x != x1) item->widget->x = x2; if (g != NULL) item->widget->x += 2; item->widget->cols = width; break; } /* forced update internal variables of inpuit line */ input_set_origin (INPUT (item->widget), item->widget->x, item->widget->cols); } break; case quick_start_groupbox: g = GROUPBOX (item->widget); if (item->widget->x != x1) item->widget->x = x2; item->widget->cols = column_width; break; case quick_stop_groupbox: g = NULL; break; case quick_separator: if (item->widget != NULL) { if (g != NULL) { Widget *wg = WIDGET (g); HLINE (item->widget)->auto_adjust_cols = FALSE; item->widget->x = wg->x + 1 - WIDGET (wg->owner)->x; item->widget->cols = wg->cols; } else if (two_columns) { HLINE (item->widget)->auto_adjust_cols = FALSE; if (item->widget->x != x1) item->widget->x = x2; item->widget->x--; item->widget->cols = column_width + 2; } else HLINE (item->widget)->auto_adjust_cols = TRUE; } break; case quick_start_columns: two_columns = TRUE; break; case quick_stop_columns: two_columns = FALSE; break; case quick_buttons: /* several buttons in bottom line */ put_buttons = TRUE; break; default: break; } if (item->widget != NULL) { unsigned long id; /* add widget into dialog */ item->widget->options |= item->quick_widget->options; /* FIXME: cannot reset flags, setup only */ id = add_widget_autopos (dd, item->widget, item->quick_widget->pos_flags, NULL); if (item->quick_widget->id != NULL) *item->quick_widget->id = id; } } while (nskip-- != 0) { dd->current = g_list_next (dd->current); if (dd->current == NULL) dd->current = dd->widgets; } return_val = run_dlg (dd); /* Get the data if we found something interesting */ if (return_val != B_CANCEL) for (i = 0; i < widgets->len; i++) { quick_widget_item_t *item; item = &g_array_index (widgets, quick_widget_item_t, i); switch (item->quick_widget->widget_type) { case quick_checkbox: *item->quick_widget->u.checkbox.state = CHECK (item->widget)->state & C_BOOL; break; case quick_input: if ((quick_widget->u.input.flags & 2) != 0) *item->quick_widget->u.input.result = tilde_expand (INPUT (item->widget)->buffer); else *item->quick_widget->u.input.result = g_strdup (INPUT (item->widget)->buffer); break; case quick_radio: *item->quick_widget->u.radio.value = RADIO (item->widget)->sel; break; default: break; } } destroy_dlg (dd); /* destroy input labels created before */ for (i = 0; i < widgets->len; i++) { quick_widget_item_t *item; item = &g_array_index (widgets, quick_widget_item_t, i); if (item->quick_widget->widget_type == quick_input) g_free (item->quick_widget->u.input.label); } g_array_free (widgets, TRUE); return return_val; }
char * history_show (GList ** history, Widget * widget, int current) { GList *z, *hlist = NULL, *hi; size_t maxlen, i, count = 0; char *r = NULL; Dlg_head *query_dlg; WListbox *query_list; history_dlg_data hist_data; if (*history == NULL) return NULL; maxlen = str_term_width1 (_("History")) + 2; for (z = *history; z != NULL; z = g_list_previous (z)) { WLEntry *entry; i = str_term_width1 ((char *) z->data); maxlen = max (maxlen, i); count++; entry = g_new0 (WLEntry, 1); /* history is being reverted here */ entry->text = g_strdup ((char *) z->data); hlist = g_list_prepend (hlist, entry); } hist_data.widget = widget; hist_data.count = count; hist_data.maxlen = maxlen; query_dlg = create_dlg (TRUE, 0, 0, 4, 4, dialog_colors, history_dlg_callback, NULL, "[History-query]", _("History"), DLG_COMPACT); query_dlg->data = &hist_data; query_list = listbox_new (1, 1, 2, 2, TRUE, NULL); /* this call makes list stick to all sides of dialog, effectively make it be resized with dialog */ add_widget_autopos (query_dlg, query_list, WPOS_KEEP_ALL, NULL); /* to avoid diplicating of (calculating sizes in two places) code, call dlg_hist_callback function here, to set dialog and controls positions. The main idea - create 4x4 dialog and add 2x2 list in center of it, and let dialog function resize it to needed size. */ history_dlg_callback (query_dlg, NULL, DLG_RESIZE, 0, NULL); if (query_dlg->y < widget->y) { /* draw list entries from bottom upto top */ listbox_set_list (query_list, hlist); if (current < 0 || (size_t) current >= count) listbox_select_last (query_list); else listbox_select_entry (query_list, count - 1 - (size_t) current); } else { /* draw list entries from top downto bottom */ /* revert history direction */ hlist = g_list_reverse (hlist); listbox_set_list (query_list, hlist); if (current > 0) listbox_select_entry (query_list, current); } if (run_dlg (query_dlg) != B_CANCEL) { char *q; listbox_get_current (query_list, &q, NULL); r = g_strdup (q); } /* get modified history from dialog */ z = NULL; for (hi = query_list->list; hi != NULL; hi = g_list_next (hi)) { WLEntry *entry; entry = (WLEntry *) hi->data; /* history is being reverted here again */ z = g_list_prepend (z, entry->text); entry->text = NULL; } /* restore history direction */ if (query_dlg->y < widget->y) z = g_list_reverse (z); destroy_dlg (query_dlg); g_list_foreach (*history, (GFunc) g_free, NULL); g_list_free (*history); *history = g_list_last (z); return r; }
unsigned long add_widget_before (Dlg_head * h, void *w, void *before) { return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP, before); }
unsigned long add_widget (Dlg_head * h, void *w) { return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP, h->current != NULL ? h->current->data : NULL); }
int add_widget (Dlg_head * h, void *w) { return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP); }