Пример #1
0
si_t shortcut_default_callback(void* self , void* msg )
{

    struct shortcut* sh = self;
    union message * m = msg;
    
    widget_default_callback(sh, m);

    switch(m->base.type)
    {
        case MESSAGE_TYPE_WIDGET_REPAINT:
            shortcut_default_widget_repaint(sh, m);
            shortcut_default_widget_show(sh, m);
            break;

        case MESSAGE_TYPE_WIDGET_SHOW:
            shortcut_default_widget_show(sh, m);
            break;

        case MESSAGE_TYPE_MOUSE_PRESS:
            shortcut_default_widget_show(sh, m);
            break;

        case MESSAGE_TYPE_MOUSE_RELEASE:
            shortcut_default_widget_show(sh, m);
            break;

        default:
            break;
    }

    return 0;
}
Пример #2
0
static cb_ret_t
groupbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WGroupbox *g = GROUPBOX (w);

    switch (msg)
    {
    case MSG_DRAW:
        {
            WDialog *h = w->owner;

            gboolean disabled;

            disabled = widget_get_state (w, WST_DISABLED);
            tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_NORMAL]);
            tty_draw_box (w->y, w->x, w->lines, w->cols, TRUE);

            if (g->title != NULL)
            {
                tty_setcolor (disabled ? DISABLED_COLOR : h->color[DLG_COLOR_TITLE]);
                widget_move (w, 0, 1);
                tty_print_string (g->title);
            }
            return MSG_HANDLED;
        }

    case MSG_DESTROY:
        g_free (g->title);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #3
0
static cb_ret_t
menubar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WMenuBar *menubar = MENUBAR (w);

    switch (msg)
    {
        /* We do not want the focus unless we have been activated */
    case MSG_FOCUS:
        if (!menubar->is_active)
            return MSG_NOT_HANDLED;

        /* Trick to get all the mouse events */
        w->lines = LINES;

        /* Trick to get all of the hotkeys */
        widget_want_hotkey (w, 1);
        menubar_draw (menubar);
        return MSG_HANDLED;

        /* We don't want the buttonbar to activate while using the menubar */
    case MSG_HOTKEY:
    case MSG_KEY:
        if (menubar->is_active)
        {
            menubar_handle_key (menubar, parm);
            return MSG_HANDLED;
        }
        return MSG_NOT_HANDLED;

    case MSG_CURSOR:
        /* Put the cursor in a suitable place */
        return MSG_NOT_HANDLED;

    case MSG_UNFOCUS:
        return menubar->is_active ? MSG_NOT_HANDLED : MSG_HANDLED;

    case MSG_DRAW:
        if (menubar->is_visible)
        {
            menubar_draw (menubar);
            return MSG_HANDLED;
        }
        /* fall through */

    case MSG_RESIZE:
        /* try show menu after screen resize */
        send_message (w, sender, MSG_FOCUS, 0, data);
        return MSG_HANDLED;


    case MSG_DESTROY:
        menubar_set_menu (menubar, NULL);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #4
0
static cb_ret_t
tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WTree *tree = (WTree *) w;
    WDialog *h = w->owner;
    WButtonBar *b;

    switch (msg)
    {
    case MSG_DRAW:
        tree_frame (h, tree);
        show_tree (tree);
        if (widget_get_state (w, WST_FOCUSED))
        {
            b = find_buttonbar (h);
            widget_redraw (WIDGET (b));
        }
        return MSG_HANDLED;

    case MSG_FOCUS:
        b = find_buttonbar (h);
        buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), tree_map, w);
        buttonbar_set_label (b, 2, Q_ ("ButtonBar|Rescan"), tree_map, w);
        buttonbar_set_label (b, 3, Q_ ("ButtonBar|Forget"), tree_map, w);
        buttonbar_set_label (b, 4, tree_navigation_flag ? Q_ ("ButtonBar|Static")
                             : Q_ ("ButtonBar|Dynamc"), tree_map, w);
        buttonbar_set_label (b, 5, Q_ ("ButtonBar|Copy"), tree_map, w);
        buttonbar_set_label (b, 6, Q_ ("ButtonBar|RenMov"), tree_map, w);
#if 0
        /* FIXME: mkdir is currently defunct */
        buttonbar_set_label (b, 7, Q_ ("ButtonBar|Mkdir"), tree_map, w);
#else
        buttonbar_clear_label (b, 7, w);
#endif
        buttonbar_set_label (b, 8, Q_ ("ButtonBar|Rmdir"), tree_map, w);

        return MSG_HANDLED;

    case MSG_UNFOCUS:
        tree->searching = 0;
        return MSG_HANDLED;

    case MSG_KEY:
        return tree_key (tree, parm);

    case MSG_ACTION:
        /* command from buttonbar */
        return tree_execute_cmd (tree, parm);

    case MSG_DESTROY:
        tree_destroy (tree);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #5
0
static cb_ret_t
listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WListbox *l = LISTBOX (w);
    cb_ret_t ret_code;

    switch (msg)
    {
    case MSG_INIT:
        return MSG_HANDLED;

    case MSG_HOTKEY:
        {
            int pos;

            pos = listbox_check_hotkey (l, parm);
            if (pos < 0)
                return MSG_NOT_HANDLED;

            listbox_run_hotkey (l, pos);

            return MSG_HANDLED;
        }

    case MSG_KEY:
        ret_code = listbox_key (l, parm);
        if (ret_code != MSG_NOT_HANDLED)
            listbox_on_change (l);
        return ret_code;

    case MSG_ACTION:
        return listbox_execute_cmd (l, parm);

    case MSG_CURSOR:
        widget_move (l, l->cursor_y, 0);
        return MSG_HANDLED;

    case MSG_FOCUS:
    case MSG_UNFOCUS:
        l->focused = msg == MSG_FOCUS;
        /* fall through */
    case MSG_DRAW:
        listbox_draw (l, l->focused);
        return MSG_HANDLED;

    case MSG_DESTROY:
        listbox_destroy (l);
        return MSG_HANDLED;

    case MSG_RESIZE:
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #6
0
static cb_ret_t
buttonbar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WButtonBar *bb = BUTTONBAR (w);
    int i;
    const char *text;

    switch (msg)
    {
    case MSG_FOCUS:
        return MSG_NOT_HANDLED;

    case MSG_HOTKEY:
        for (i = 0; i < BUTTONBAR_LABELS_NUM; i++)
            if (parm == KEY_F (i + 1) && buttonbar_call (bb, i))
                return MSG_HANDLED;
        return MSG_NOT_HANDLED;

    case MSG_DRAW:
        if (bb->visible)
        {
            buttonbar_init_button_positions (bb);
            widget_move (w, 0, 0);
            tty_setcolor (DEFAULT_COLOR);
            tty_printf ("%-*s", w->cols, "");
            widget_move (w, 0, 0);

            for (i = 0; i < BUTTONBAR_LABELS_NUM; i++)
            {
                int width;

                width = buttonbar_get_button_width (bb, i);
                if (width <= 0)
                    break;

                tty_setcolor (BUTTONBAR_HOTKEY_COLOR);
                tty_printf ("%2d", i + 1);

                tty_setcolor (BUTTONBAR_BUTTON_COLOR);
                text = (bb->labels[i].text != NULL) ? bb->labels[i].text : "";
                tty_print_string (str_fit_to_term (text, width - 2, J_LEFT_FIT));
            }
        }
        return MSG_HANDLED;

    case MSG_DESTROY:
        for (i = 0; i < BUTTONBAR_LABELS_NUM; i++)
            g_free (bb->labels[i].text);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #7
0
static cb_ret_t
md_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    switch (msg)
    {
    case MSG_RESIZE:
        w->lines = help_lines;
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #8
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);
    }
}
Пример #9
0
static cb_ret_t
groupbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WGroupbox *g = GROUPBOX (w);

    switch (msg)
    {
    case MSG_INIT:
        return MSG_HANDLED;

    case MSG_FOCUS:
        return MSG_NOT_HANDLED;

    case MSG_DRAW:
        {
            gboolean disabled;

            disabled = (w->options & W_DISABLED) != 0;
            tty_setcolor (disabled ? DISABLED_COLOR : COLOR_NORMAL);
            tty_draw_box (w->y, w->x, w->lines, w->cols, TRUE);

            if (g->title != NULL)
            {
                Widget *wo = WIDGET (w->owner);

                tty_setcolor (disabled ? DISABLED_COLOR : COLOR_TITLE);
                widget_move (wo, w->y - wo->y, w->x - wo->x + 1);
                tty_print_string (g->title);
            }
            return MSG_HANDLED;
        }

    case MSG_DESTROY:
        g_free (g->title);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #10
0
si_t spinbox_default_callback(addr_t self, addr_t msg)
{
    struct spinbox * b = self;
    union message * m = msg;
    
    widget_default_callback(b, m);

    switch(m->base.type)
    {
        case MESSAGE_TYPE_WIDGET_REPAINT:
            spinbox_default_widget_repaint(b, m);
            spinbox_default_widget_show(b, m);
            break;

        case MESSAGE_TYPE_WIDGET_SHOW:
            spinbox_default_widget_show(b, m);
            break;

        default:
            break;
    }

    return 0;
}
Пример #11
0
static cb_ret_t
listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WListbox *l = LISTBOX (w);
    WDialog *h = w->owner;
    cb_ret_t ret_code;

    switch (msg)
    {
    case MSG_INIT:
        return MSG_HANDLED;

    case MSG_HOTKEY:
        {
            int pos, action;

            pos = listbox_check_hotkey (l, parm);
            if (pos < 0)
                return MSG_NOT_HANDLED;

            listbox_select_entry (l, pos);
            send_message (h, w, MSG_ACTION, l->pos, NULL);

            if (l->callback != NULL)
                action = l->callback (l);
            else
                action = LISTBOX_DONE;

            if (action == LISTBOX_DONE)
            {
                h->ret_value = B_ENTER;
                dlg_stop (h);
            }

            return MSG_HANDLED;
        }

    case MSG_KEY:
        ret_code = listbox_key (l, parm);
        if (ret_code != MSG_NOT_HANDLED)
        {
            listbox_draw (l, TRUE);
            send_message (h, w, MSG_ACTION, l->pos, NULL);
        }
        return ret_code;

    case MSG_ACTION:
        return listbox_execute_cmd (l, parm);

    case MSG_CURSOR:
        widget_move (l, l->cursor_y, 0);
        send_message (h, w, MSG_ACTION, l->pos, NULL);
        return MSG_HANDLED;

    case MSG_FOCUS:
    case MSG_UNFOCUS:
    case MSG_DRAW:
        listbox_draw (l, msg != MSG_UNFOCUS);
        return MSG_HANDLED;

    case MSG_DESTROY:
        listbox_destroy (l);
        return MSG_HANDLED;

    case MSG_RESIZE:
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #12
0
static cb_ret_t
edit_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WEdit *e = (WEdit *) w;

    switch (msg)
    {
    case MSG_FOCUS:
        edit_set_buttonbar (e, find_buttonbar (w->owner));
        return MSG_HANDLED;

    case MSG_DRAW:
        e->force |= REDRAW_COMPLETELY;
        edit_update_screen (e);
        return MSG_HANDLED;

    case MSG_KEY:
        {
            int cmd, ch;
            cb_ret_t ret = MSG_NOT_HANDLED;

            /* The user may override the access-keys for the menu bar. */
            if (macro_index == -1 && edit_execute_macro (e, parm))
            {
                edit_update_screen (e);
                ret = MSG_HANDLED;
            }
            else if (edit_translate_key (e, parm, &cmd, &ch))
            {
                edit_execute_key_command (e, cmd, ch);
                edit_update_screen (e);
                ret = MSG_HANDLED;
            }

            return ret;
        }

    case MSG_ACTION:
        /* command from menubar or buttonbar */
        edit_execute_key_command (e, parm, -1);
        edit_update_screen (e);
        return MSG_HANDLED;

    case MSG_CURSOR:
        {
            int y, x;

            y = (e->fullscreen ? 0 : 1) + EDIT_TEXT_VERTICAL_OFFSET + e->curs_row;
            x = (e->fullscreen ? 0 : 1) + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width +
                e->curs_col + e->start_col + e->over_col;

            widget_move (w, y, x);
            return MSG_HANDLED;
        }

    case MSG_IDLE:
        edit_update_screen (e);
        return MSG_HANDLED;

    case MSG_DESTROY:
        edit_clean (e);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #13
0
static cb_ret_t
gauge_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WGauge *g = GAUGE (w);
    WDialog *h = w->owner;

    switch (msg)
    {
    case MSG_INIT:
        return MSG_HANDLED;

        /* We don't want to get the focus */
    case MSG_FOCUS:
        return MSG_NOT_HANDLED;

    case MSG_DRAW:
        widget_move (w, 0, 0);
        if (!g->shown)
        {
            tty_setcolor (h->color[DLG_COLOR_NORMAL]);
            tty_printf ("%*s", w->cols, "");
        }
        else
        {
            int gauge_len;
            int percentage, columns;
            long total = g->max;
            long done = g->current;

            if (total <= 0 || done < 0)
            {
                done = 0;
                total = 100;
            }
            if (done > total)
                done = total;
            while (total > 65535)
            {
                total /= 256;
                done /= 256;
            }

            gauge_len = w->cols - 7;    /* 7 positions for percentage */

            percentage = (200 * done / total + 1) / 2;
            columns = (2 * gauge_len * done / total + 1) / 2;
            tty_print_char ('[');
            if (g->from_left_to_right)
            {
                tty_setcolor (GAUGE_COLOR);
                tty_printf ("%*s", columns, "");
                tty_setcolor (h->color[DLG_COLOR_NORMAL]);
                tty_printf ("%*s] %3d%%", gauge_len - columns, "", percentage);
            }
            else
            {
                tty_setcolor (h->color[DLG_COLOR_NORMAL]);
                tty_printf ("%*s", gauge_len - columns, "");
                tty_setcolor (GAUGE_COLOR);
                tty_printf ("%*s", columns, "");
                tty_setcolor (h->color[DLG_COLOR_NORMAL]);
                tty_printf ("] %3d%%", percentage);
            }
        }
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #14
0
static cb_ret_t
hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WHLine *l = HLINE (w);
    WDialog *h = w->owner;

    switch (msg)
    {
    case MSG_INIT:
    case MSG_RESIZE:
        if (l->auto_adjust_cols)
        {
            Widget *wo = WIDGET (h);

            if (((h->flags & DLG_COMPACT) != 0))
            {
                w->x = wo->x;
                w->cols = wo->cols;
            }
            else
            {
                w->x = wo->x + 1;
                w->cols = wo->cols - 2;
            }
        }
        return MSG_HANDLED;

    case MSG_FOCUS:
        /* We don't want to get the focus */
        return MSG_NOT_HANDLED;

    case MSG_DRAW:
        if (l->transparent)
            tty_setcolor (DEFAULT_COLOR);
        else
            tty_setcolor (h->color[DLG_COLOR_NORMAL]);

        tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2);

        if (l->auto_adjust_cols)
        {
            widget_move (w, 0, 0);
            tty_print_alt_char (ACS_LTEE, FALSE);
            widget_move (w, 0, w->cols - 1);
            tty_print_alt_char (ACS_RTEE, FALSE);
        }

        if (l->text != NULL)
        {
            int text_width;

            text_width = str_term_width1 (l->text);
            widget_move (w, 0, (w->cols - text_width) / 2);
            tty_print_string (l->text);
        }
        return MSG_HANDLED;

    case MSG_DESTROY:
        g_free (l->text);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Пример #15
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);
    }
}