Exemple #1
0
/** Both views */
static gboolean
do_mcview_event (mcview_t * view, Gpm_Event * event, int *result)
{
    screen_dimen y, x;
    Gpm_Event local;
    Widget *w = WIDGET (view);

    /* rest of the upper frame - call menu */
    if (mcview_is_in_panel (view) && (event->type & GPM_DOWN) != 0 &&
        event->y == WIDGET (w->owner)->y + 1)
    {
        *result = MOU_UNHANDLED;
        return FALSE;           /* don't draw viewer over menu */
    }

    *result = MOU_NORMAL;

    local = mouse_get_local (event, w);

    /* We are not interested in the release events */
    if ((local.type & (GPM_DOWN | GPM_DRAG)) == 0)
        return FALSE;

    /* Wheel events */
    if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0)
    {
        mcview_move_up (view, 2);
        return TRUE;
    }
    if ((local.buttons & GPM_B_DOWN) != 0 && (local.type & GPM_DOWN) != 0)
    {
        mcview_move_down (view, 2);
        return TRUE;
    }

    x = local.x;
    y = local.y;

    /* Scrolling left and right */
    if (!view->text_wrap_mode)
    {
        if (x < view->data_area.width * 1 / 4)
        {
            mcview_move_left (view, 1);
            goto processed;
        }

        if (x < view->data_area.width * 3 / 4)
        {
            /* ignore the click */
        }
        else
        {
            mcview_move_right (view, 1);
            goto processed;
        }
    }

    /* Scrolling up and down */
    if (y < view->data_area.top + view->data_area.height * 1 / 3)
    {
        if (mcview_mouse_move_pages)
            mcview_move_up (view, view->data_area.height / 2);
        else
            mcview_move_up (view, 1);
        goto processed;
    }
    else if (y < view->data_area.top + view->data_area.height * 2 / 3)
    {
        /* ignore the click */
    }
    else
    {
        if (mcview_mouse_move_pages)
            mcview_move_down (view, view->data_area.height / 2);
        else
            mcview_move_down (view, 1);
        goto processed;
    }

    return FALSE;

  processed:
    *result = MOU_REPEAT;
    return TRUE;
}
Exemple #2
0
static void
mcview_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
{
    WView *view = (WView *) w;
    gboolean ok = TRUE;

    switch (msg)
    {
    case MSG_MOUSE_DOWN:
        if (mcview_is_in_panel (view))
        {
            if (event->y == WIDGET (w->owner)->y)
            {
                /* return MOU_UNHANDLED */
                event->result.abort = TRUE;
                /* don't draw viewer over menu */
                ok = FALSE;
                break;
            }

            if (!view->active)
            {
                /* Grab focus */
                change_panel ();
            }
        }
        /* fall throught */

    case MSG_MOUSE_CLICK:
        if (!view->text_wrap_mode)
        {
            /* Scrolling left and right */
            screen_dimen x;

            x = event->x + 1;   /* FIXME */

            if (x < view->data_area.width * 1 / 4)
            {
                mcview_move_left (view, 1);
                event->result.repeat = msg == MSG_MOUSE_DOWN;
            }
            else if (x < view->data_area.width * 3 / 4)
            {
                /* ignore the click */
                ok = FALSE;
            }
            else
            {
                mcview_move_right (view, 1);
                event->result.repeat = msg == MSG_MOUSE_DOWN;
            }
        }
        else
        {
            /* Scrolling up and down */
            screen_dimen y;

            y = event->y + 1;   /* FIXME */

            if (y < view->data_area.top + view->data_area.height * 1 / 3)
            {
                if (mcview_mouse_move_pages)
                    mcview_move_up (view, view->data_area.height / 2);
                else
                    mcview_move_up (view, 1);

                event->result.repeat = msg == MSG_MOUSE_DOWN;
            }
            else if (y < view->data_area.top + view->data_area.height * 2 / 3)
            {
                /* ignore the click */
                ok = FALSE;
            }
            else
            {
                if (mcview_mouse_move_pages)
                    mcview_move_down (view, view->data_area.height / 2);
                else
                    mcview_move_down (view, 1);

                event->result.repeat = msg == MSG_MOUSE_DOWN;
            }
        }
        break;

    case MSG_MOUSE_SCROLL_UP:
        mcview_move_up (view, 2);
        break;

    case MSG_MOUSE_SCROLL_DOWN:
        mcview_move_down (view, 2);
        break;

    default:
        ok = FALSE;
        break;
    }

    if (ok)
        mcview_update (view);
}