Пример #1
0
void
destroy_menu (menu_t * menu)
{
    release_hotkey (menu->text);
    g_list_free_full (menu->entries, (GDestroyNotify) menu_entry_free);
    g_free (menu->help_node);
    g_free (menu);
}
Пример #2
0
Файл: button.c Проект: 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);
}
Пример #3
0
Файл: menu.c Проект: ryanlee/mc
void
destroy_menu (Menu * menu)
{
    release_hotkey (menu->text);
    g_list_foreach (menu->entries, (GFunc) menu_entry_free, NULL);
    g_list_free (menu->entries);
    g_free (menu->help_node);
    g_free (menu);
}
Пример #4
0
void
menu_entry_free (menu_entry_t * entry)
{
    if (entry != NULL)
    {
        release_hotkey (entry->text);
        g_free (entry->shortcut);
        g_free (entry);
    }
}
Пример #5
0
Файл: check.c Проект: BrEacK/mc
static cb_ret_t
check_callback (Widget * w, widget_msg_t msg, int parm)
{
    WCheck *c = (WCheck *) w;
    Dlg_head *h = c->widget.owner;

    switch (msg)
    {
    case WIDGET_HOTKEY:
        if (c->text.hotkey != NULL)
        {
            if (g_ascii_tolower ((gchar) c->text.hotkey[0]) == parm)
            {
                check_callback (w, WIDGET_KEY, ' ');    /* make action */
                return MSG_HANDLED;
            }
        }
        return MSG_NOT_HANDLED;

    case WIDGET_KEY:
        if (parm != ' ')
            return MSG_NOT_HANDLED;
        c->state ^= C_BOOL;
        c->state ^= C_CHANGE;
        h->callback (h, w, DLG_ACTION, 0, NULL);
        check_callback (w, WIDGET_FOCUS, ' ');
        return MSG_HANDLED;

    case WIDGET_CURSOR:
        widget_move (&c->widget, 0, 1);
        return MSG_HANDLED;

    case WIDGET_FOCUS:
    case WIDGET_UNFOCUS:
    case WIDGET_DRAW:
        widget_selectcolor (w, msg == WIDGET_FOCUS, FALSE);
        widget_move (&c->widget, 0, 0);
        tty_print_string ((c->state & C_BOOL) ? "[x] " : "[ ] ");
        hotkey_draw (w, c->text, msg == WIDGET_FOCUS);
        return MSG_HANDLED;

    case WIDGET_DESTROY:
        release_hotkey (c->text);
        return MSG_HANDLED;

    default:
        return default_proc (msg, parm);
    }
}
Пример #6
0
static cb_ret_t
check_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WCheck *c = CHECK (w);

    switch (msg)
    {
    case MSG_HOTKEY:
        if (c->text.hotkey != NULL)
        {
            if (g_ascii_tolower ((gchar) c->text.hotkey[0]) == parm)
            {
                /* make action */
                send_message (w, sender, MSG_KEY, ' ', data);
                return MSG_HANDLED;
            }
        }
        return MSG_NOT_HANDLED;

    case MSG_KEY:
        if (parm != ' ')
            return MSG_NOT_HANDLED;
        c->state ^= C_BOOL;
        c->state ^= C_CHANGE;
        send_message (w, sender, MSG_FOCUS, ' ', data);
        send_message (WIDGET (w)->owner, w, MSG_NOTIFY, 0, NULL);
        return MSG_HANDLED;

    case MSG_CURSOR:
        widget_move (c, 0, 1);
        return MSG_HANDLED;

    case MSG_FOCUS:
    case MSG_UNFOCUS:
    case MSG_DRAW:
        widget_selectcolor (w, msg == MSG_FOCUS, FALSE);
        widget_move (c, 0, 0);
        tty_print_string ((c->state & C_BOOL) ? "[x] " : "[ ] ");
        hotkey_draw (w, c->text, msg == MSG_FOCUS);
        return MSG_HANDLED;

    case MSG_DESTROY:
        release_hotkey (c->text);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #7
0
Файл: button.c Проект: artzub/mc
static cb_ret_t
button_callback (Widget * w, widget_msg_t msg, int parm)
{
    WButton *b = (WButton *) w;
    int stop = 0;
    int off = 0;
    Dlg_head *h = b->widget.owner;

    switch (msg)
    {
    case WIDGET_HOTKEY:
        /*
         * Don't let the default button steal Enter from the current
         * button.  This is a workaround for the flawed event model
         * when hotkeys are sent to all widgets before the key is
         * handled by the current widget.
         */
        if (parm == '\n' && (Widget *) h->current->data == &b->widget)
        {
            button_callback (w, WIDGET_KEY, ' ');
            return MSG_HANDLED;
        }

        if (parm == '\n' && b->flags == DEFPUSH_BUTTON)
        {
            button_callback (w, WIDGET_KEY, ' ');
            return MSG_HANDLED;
        }

        if (b->text.hotkey != NULL &&
            g_ascii_tolower ((gchar) b->text.hotkey[0]) == parm)
        {
            button_callback (w, WIDGET_KEY, ' ');
            return MSG_HANDLED;
        }
        return MSG_NOT_HANDLED;

    case WIDGET_KEY:
        if (parm != ' ' && parm != '\n')
            return MSG_NOT_HANDLED;

        if (b->callback != NULL)
            stop = b->callback (b, b->action);
        if (b->callback == NULL || stop != 0)
        {
            h->ret_value = b->action;
            dlg_stop (h);
        }
        return MSG_HANDLED;

    case WIDGET_CURSOR:
        switch (b->flags)
        {
        case DEFPUSH_BUTTON:
            off = 3;
            break;
        case NORMAL_BUTTON:
            off = 2;
            break;
        case NARROW_BUTTON:
            off = 1;
            break;
        case HIDDEN_BUTTON:
        default:
            off = 0;
            break;
        }
        widget_move (&b->widget, 0, b->hotpos + off);
        return MSG_HANDLED;

    case WIDGET_UNFOCUS:
    case WIDGET_FOCUS:
    case WIDGET_DRAW:
        if (msg == WIDGET_UNFOCUS)
            b->selected = FALSE;
        else if (msg == WIDGET_FOCUS)
            b->selected = TRUE;

        widget_selectcolor (w, b->selected, FALSE);
        widget_move (w, 0, 0);

        switch (b->flags)
        {
        case DEFPUSH_BUTTON:
            tty_print_string ("[< ");
            break;
        case NORMAL_BUTTON:
            tty_print_string ("[ ");
            break;
        case NARROW_BUTTON:
            tty_print_string ("[");
            break;
        case HIDDEN_BUTTON:
        default:
            return MSG_HANDLED;
        }

        hotkey_draw (w, b->text, b->selected);

        switch (b->flags)
        {
        case DEFPUSH_BUTTON:
            tty_print_string (" >]");
            break;
        case NORMAL_BUTTON:
            tty_print_string (" ]");
            break;
        case NARROW_BUTTON:
            tty_print_string ("]");
            break;
        default:
            break;
        }
        return MSG_HANDLED;

    case WIDGET_DESTROY:
        release_hotkey (b->text);
        return MSG_HANDLED;

    default:
        return default_proc (msg, parm);
    }
}
Пример #8
0
void
menu_set_name (menu_t * menu, const char *name)
{
    release_hotkey (menu->text);
    menu->text = parse_hotkey (name);
}
Пример #9
0
Файл: radio.c Проект: LubkaB/mc
static cb_ret_t
radio_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WRadio *r = RADIO (w);
    int i;

    switch (msg)
    {
    case MSG_HOTKEY:
        {
            for (i = 0; i < r->count; i++)
            {
                if (r->texts[i].hotkey != NULL)
                {
                    int c = g_ascii_tolower ((gchar) r->texts[i].hotkey[0]);

                    if (c != parm)
                        continue;
                    r->pos = i;

                    /* Take action */
                    send_message (w, sender, MSG_KEY, ' ', data);
                    return MSG_HANDLED;
                }
            }
        }
        return MSG_NOT_HANDLED;

    case MSG_KEY:
        switch (parm)
        {
        case ' ':
            r->sel = r->pos;
            send_message (w->owner, w, MSG_ACTION, 0, NULL);
            send_message (w, sender, MSG_FOCUS, ' ', data);
            return MSG_HANDLED;

        case KEY_UP:
        case KEY_LEFT:
            if (r->pos > 0)
            {
                r->pos--;
                return MSG_HANDLED;
            }
            return MSG_NOT_HANDLED;

        case KEY_DOWN:
        case KEY_RIGHT:
            if (r->count - 1 > r->pos)
            {
                r->pos++;
                return MSG_HANDLED;
            }
        }
        return MSG_NOT_HANDLED;

    case MSG_CURSOR:
        send_message (w->owner, w, MSG_ACTION, 0, NULL);
        send_message (w, sender, MSG_FOCUS, ' ', data);
        widget_move (r, r->pos, 1);
        return MSG_HANDLED;

    case MSG_UNFOCUS:
    case MSG_FOCUS:
    case MSG_DRAW:
        for (i = 0; i < r->count; i++)
        {
            const gboolean focused = (i == r->pos && msg == MSG_FOCUS);

            widget_selectcolor (w, focused, FALSE);
            widget_move (r, i, 0);
            tty_draw_hline (w->y + i, w->x, ' ', w->cols);
            tty_print_string ((r->sel == i) ? "(*) " : "( ) ");
            hotkey_draw (w, r->texts[i], focused);
        }
        return MSG_HANDLED;

    case MSG_DESTROY:
        for (i = 0; i < r->count; i++)
            release_hotkey (r->texts[i]);
        g_free (r->texts);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}