Пример #1
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);
    }
}
Пример #2
0
static void
buttonbar_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
{
    switch (msg)
    {
    case MSG_MOUSE_CLICK:
        {
            WButtonBar *bb = BUTTONBAR (w);
            int button;

            button = buttonbar_get_button_by_x_coord (bb, event->x);
            if (button >= 0)
                buttonbar_call (bb, button);
            break;
        }

    default:
        break;
    }
}
Пример #3
0
static int
buttonbar_event (Gpm_Event * event, void *data)
{
    Widget *w = WIDGET (data);

    if (!mouse_global_in_widget (event, w))
        return MOU_UNHANDLED;

    if ((event->type & GPM_UP) != 0)
    {
        WButtonBar *bb = BUTTONBAR (data);
        Gpm_Event local;
        int button;

        local = mouse_get_local (event, w);
        button = buttonbar_get_button_by_x_coord (bb, local.x - 1);
        if (button >= 0)
            buttonbar_call (bb, button);
    }

    return MOU_NORMAL;
}
Пример #4
0
/* Find ButtonBar widget in the dialog */
WButtonBar *
find_buttonbar (const WDialog * h)
{
    return BUTTONBAR (find_widget_type (h, buttonbar_callback));
}