Example #1
0
File: button.c Project: artzub/mc
void
button_set_text (WButton * b, const char *text)
{
    release_hotkey (b->text);
    b->text = parse_hotkey (text);
    b->widget.cols = button_get_len (b);
    dlg_redraw (b->widget.owner);
}
Example #2
0
File: button.c Project: artzub/mc
WButton *
button_new (int y, int x, int action, button_flags_t flags, const char *text, bcback_fn callback)
{
    WButton *b;

    b = g_new (WButton, 1);
    b->action = action;
    b->flags = flags;
    b->text = parse_hotkey (text);

    init_widget (&b->widget, y, x, 1, button_get_len (b), button_callback, button_event);

    b->selected = FALSE;
    b->callback = callback;
    widget_want_hotkey (b->widget, TRUE);
    b->hotpos = (b->text.hotkey != NULL) ? str_term_width1 (b->text.start) : -1;

    return b;
}
Example #3
0
File: filegui.c Project: CTU-OSP/mc
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);
}
Example #4
0
static Dlg_head *
display_init (int radio_sel, char *init_text, int _check_status, char **_status)
{
    int dlg_width = 48, dlg_height = 15;
    Dlg_head *dd;

    /* Controls whether the array strings have been translated */
    const char *displays[LIST_TYPES] = {
        N_("&Full file list"),
        N_("&Brief file list"),
        N_("&Long file list"),
        N_("&User defined:")
    };

    /* Index in displays[] for "user defined" */
    const int user_type_idx = 3;

    const char *display_title = N_("Listing mode");
    const char *user_mini_status = N_("User &mini status");
    const char *ok_name = N_("&OK");
    const char *cancel_name = N_("&Cancel");

    WButton *ok_button, *cancel_button;

    {
        int i, maxlen = 0;
        const char *cp;
        int ok_len, cancel_len, b_len, gap;

#ifdef ENABLE_NLS
        display_title = _(display_title);
        user_mini_status = _(user_mini_status);
        ok_name = _(ok_name);
        cancel_name = _(cancel_name);

        for (i = 0; i < LIST_TYPES; i++)
            displays[i] = _(displays[i]);
#endif

        /* get hotkey of user-defined format string */
        cp = strchr (displays[user_type_idx], '&');
        if (cp != NULL && *++cp != '\0')
            display_user_hotkey = g_ascii_tolower (*cp);

        /* xpos will be fixed later */
        ok_button = button_new (dlg_height - 3, 0, B_ENTER, DEFPUSH_BUTTON, ok_name, 0);
        ok_len = button_get_len (ok_button);
        cancel_button = button_new (dlg_height - 3, 0, B_CANCEL, NORMAL_BUTTON, cancel_name, 0);
        cancel_len = button_get_len (cancel_button);
        b_len = ok_len + cancel_len + 2;

        dlg_width = max (dlg_width, str_term_width1 (display_title) + 10);
        /* calculate max width of radiobutons */
        for (i = 0; i < LIST_TYPES; i++)
            maxlen = max (maxlen, str_term_width1 (displays[i]));
        dlg_width = max (dlg_width, maxlen);
        dlg_width = max (dlg_width, str_term_width1 (user_mini_status) + 13);

        /* buttons */
        dlg_width = max (dlg_width, b_len + 6);
        gap = (dlg_width - 6 - b_len) / 3;
        ok_button->widget.x = 3 + gap;
        cancel_button->widget.x = ok_button->widget.x + ok_len + gap + 2;
    }

    displays_status = _status;

    dd = create_dlg (TRUE, 0, 0, dlg_height, dlg_width, dialog_colors,
                     display_callback, "[Listing Mode...]", display_title,
                     DLG_CENTER | DLG_REVERSE);

    add_widget (dd, cancel_button);
    add_widget (dd, ok_button);

    display_mini_status =
        input_new (10, 8, input_get_default_colors (), dlg_width - 12, _status[radio_sel],
                   "mini-input", INPUT_COMPLETE_DEFAULT);
    add_widget (dd, display_mini_status);

    display_check_status = check_new (9, 4, _check_status, user_mini_status);
    add_widget (dd, display_check_status);

    display_user_format = input_new (7, 8, input_get_default_colors (), dlg_width - 12, init_text,
                                     "user-fmt-input", INPUT_COMPLETE_DEFAULT);
    add_widget (dd, display_user_format);

    display_radio = radio_new (3, 4, LIST_TYPES, displays);
    display_radio->sel = display_radio->pos = radio_sel;
    add_widget (dd, display_radio);

    return dd;
}
Example #5
0
File: panelize.c Project: andi5/mc
static void
init_panelize (void)
{
    struct
    {
        int ret_cmd;
        button_flags_t flags;
        const char *text;
    } panelize_but[] =
    {
        /* *INDENT-OFF* */
        { B_ENTER, DEFPUSH_BUTTON, N_("Pane&lize") },
        { B_REMOVE, NORMAL_BUTTON, N_("&Remove") },
        { B_ADD, NORMAL_BUTTON, N_("&Add new") },
        { B_CANCEL, NORMAL_BUTTON, N_("&Cancel") }
        /* *INDENT-ON* */
    };

    size_t i;
    int blen;
    int panelize_cols;
    struct panelize *current;
    int x, y;

    last_listitem = 0;

    do_refresh ();

    i = G_N_ELEMENTS (panelize_but);
    blen = i - 1;               /* gaps between buttons */
    while (i-- != 0)
    {
#ifdef ENABLE_NLS
        panelize_but[i].text = _(panelize_but[i].text);
#endif
        blen += str_term_width1 (panelize_but[i].text) + 3 + 1;
        if (panelize_but[i].flags == DEFPUSH_BUTTON)
            blen += 2;
    }

    panelize_cols = COLS - 6;
    panelize_cols = max (panelize_cols, blen + 4);

    panelize_dlg =
        dlg_create (TRUE, 0, 0, 20, panelize_cols, dialog_colors, panelize_callback, NULL,
                    "[External panelize]", _("External panelize"), DLG_CENTER);

    /* add listbox to the dialogs */
    y = UY;
    add_widget (panelize_dlg, groupbox_new (y++, UX, 12, panelize_cols - UX * 2, ""));

    l_panelize = listbox_new (y, UX + 1, 10, panelize_cols - UX * 2 - 2, FALSE, NULL);
    for (current = panelize; current != NULL; current = current->next)
        listbox_add_item (l_panelize, LISTBOX_APPEND_AT_END, 0, current->label, current);
    listbox_select_entry (l_panelize, listbox_search_text (l_panelize, _("Other command")));
    add_widget (panelize_dlg, l_panelize);

    y += WIDGET (l_panelize)->lines + 1;
    add_widget (panelize_dlg, label_new (y++, UX, _("Command")));
    pname =
        input_new (y++, UX, input_colors, panelize_cols - UX * 2, "", "in",
                   INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_HOSTNAMES | INPUT_COMPLETE_COMMANDS |
                   INPUT_COMPLETE_VARIABLES | INPUT_COMPLETE_USERNAMES | INPUT_COMPLETE_CD |
                   INPUT_COMPLETE_SHELL_ESC);
    add_widget (panelize_dlg, pname);



    add_widget (panelize_dlg, hline_new (y++, -1, -1));

    x = (panelize_cols - blen) / 2;
    for (i = 0; i < G_N_ELEMENTS (panelize_but); i++)
    {
        WButton *b;

        b = button_new (y, x,
                        panelize_but[i].ret_cmd, panelize_but[i].flags, panelize_but[i].text, NULL);
        add_widget (panelize_dlg, b);

        x += button_get_len (b) + 1;
    }

    dlg_select_widget (l_panelize);
}