예제 #1
0
파일: radio.c 프로젝트: LubkaB/mc
static int
radio_event (Gpm_Event * event, void *data)
{
    Widget *w = WIDGET (data);

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

    if ((event->type & (GPM_DOWN | GPM_UP)) != 0)
    {
        WRadio *r = RADIO (data);
        Gpm_Event local;

        local = mouse_get_local (event, w);

        r->pos = local.y - 1;
        dlg_select_widget (w);
        if ((event->type & GPM_UP) != 0)
        {
            radio_callback (w, NULL, MSG_KEY, ' ', NULL);
            send_message (w->owner, w, MSG_POST_KEY, ' ', NULL);
        }
    }

    return MOU_NORMAL;
}
예제 #2
0
파일: tree.c 프로젝트: GalaxyTab4/workbench
static int
tree_event (Gpm_Event * event, void *data)
{
    WTree *tree = (WTree *) data;
    Widget *w = WIDGET (data);
    Gpm_Event local;

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

    /* rest of the upper frame - call menu */
    if (tree->is_panel && (event->type & GPM_DOWN) != 0 && event->y == WIDGET (w->owner)->y + 1)
        return MOU_UNHANDLED;

    local = mouse_get_local (event, w);

    if ((local.type & GPM_UP) == 0)
        return MOU_NORMAL;

    if (tree->is_panel)
        local.y--;

    local.y--;

    if (!tree->active)
        change_panel ();

    if (local.y < 0)
    {
        tree_move_backward (tree, tlines (tree) - 1);
        show_tree (tree);
    }
    else if (local.y >= tlines (tree))
    {
        tree_move_forward (tree, tlines (tree) - 1);
        show_tree (tree);
    }
    else if ((local.type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
    {
        if (tree->tree_shown[local.y] != NULL)
        {
            tree->selected_ptr = tree->tree_shown[local.y];
            tree->topdiff = local.y;
        }
        tree_chdir_sel (tree);
    }

    return MOU_NORMAL;
}
예제 #3
0
파일: tree.c 프로젝트: ryanlee/mc
static int
tree_event (Gpm_Event * event, void *data)
{
    WTree *tree = (WTree *) data;
    Widget *w = (Widget *) data;
    Gpm_Event local;

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

    local = mouse_get_local (event, w);

    /* rest of the upper frame, the menu is invisible - call menu */
    if (tree->is_panel && (local.type & GPM_DOWN) != 0 && local.y == 1 && !menubar_visible)
        return the_menubar->widget.mouse (event, the_menubar);

    if ((local.type & GPM_UP) == 0)
        return MOU_NORMAL;

    if (tree->is_panel)
        local.y--;

    local.y--;

    if (!tree->active)
        change_panel ();

    if (local.y < 0)
    {
        tree_move_backward (tree, tlines (tree) - 1);
        show_tree (tree);
    }
    else if (local.y >= tlines (tree))
    {
        tree_move_forward (tree, tlines (tree) - 1);
        show_tree (tree);
    }
    else
    {
        tree_mouse_click (tree, local.y);
        if ((local.type & (GPM_UP | GPM_DOUBLE)) == (GPM_UP | GPM_DOUBLE))
            tree_chdir_sel (tree);
    }

    return MOU_NORMAL;
}
예제 #4
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;
}
예제 #5
0
파일: listbox.c 프로젝트: Distrotech/mc
static int
listbox_event (Gpm_Event * event, void *data)
{
    WListbox *l = LISTBOX (data);
    Widget *w = WIDGET (data);

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

    /* Single click */
    if ((event->type & GPM_DOWN) != 0)
        dlg_select_widget (l);

    if (listbox_is_empty (l))
        return MOU_NORMAL;

    if ((event->type & (GPM_DOWN | GPM_DRAG)) != 0)
    {
        int ret = MOU_REPEAT;
        Gpm_Event local;
        int i;

        local = mouse_get_local (event, w);
        if (local.y < 1)
            for (i = -local.y; i >= 0; i--)
                listbox_back (l);
        else if (local.y > w->lines)
            for (i = local.y - w->lines; i > 0; i--)
                listbox_fwd (l);
        else if ((local.buttons & GPM_B_UP) != 0)
        {
            listbox_back (l);
            ret = MOU_NORMAL;
        }
        else if ((local.buttons & GPM_B_DOWN) != 0)
        {
            listbox_fwd (l);
            ret = MOU_NORMAL;
        }
        else
            listbox_select_entry (l, listbox_select_pos (l, l->top, local.y - 1));

        /* We need to refresh ourselves since the dialog manager doesn't */
        /* know about this event */
        listbox_draw (l, TRUE);
        return ret;
    }

    /* Double click */
    if ((event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE))
    {
        Gpm_Event local;
        int action;

        local = mouse_get_local (event, w);
        dlg_select_widget (l);
        listbox_select_entry (l, listbox_select_pos (l, l->top, local.y - 1));

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

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

    return MOU_NORMAL;
}
예제 #6
0
파일: help.c 프로젝트: GarothLongint/mc
static int
help_event (Gpm_Event * event, void *vp)
{
    Widget *w = WIDGET (vp);
    GSList *current_area;
    Gpm_Event local;

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

    if ((event->type & GPM_UP) == 0)
        return MOU_NORMAL;

    local = mouse_get_local (event, w);

    /* The event is relative to the dialog window, adjust it: */
    local.x -= 2;
    local.y -= 2;

    if ((local.buttons & GPM_B_RIGHT) != 0)
    {
        currentpoint = history[history_ptr].page;
        selected_item = history[history_ptr].link;
        history_ptr--;
        if (history_ptr < 0)
            history_ptr = HISTORY_SIZE - 1;

        send_message (w->owner, NULL, MSG_DRAW, 0, NULL);
        return MOU_NORMAL;
    }

    /* Test whether the mouse click is inside one of the link areas */
    for (current_area = link_area; current_area != NULL; current_area = g_slist_next (current_area))
    {
        Link_Area *la = (Link_Area *) current_area->data;

        /* Test one line link area */
        if (local.y == la->y1 && local.x >= la->x1 && local.y == la->y2 && local.x <= la->x2)
            break;

        /* Test two line link area */
        if (la->y1 + 1 == la->y2)
        {
            /* The first line */
            if (local.y == la->y1 && local.x >= la->x1)
                break;
            /* The second line */
            if (local.y == la->y2 && local.x <= la->x2)
                break;
        }
        /* Mouse will not work with link areas of more than two lines */
    }

    /* Test whether a link area was found */
    if (current_area != NULL)
    {
        Link_Area *la = (Link_Area *) current_area->data;

        /* The click was inside a link area -> follow the link */
        history_ptr = (history_ptr + 1) % HISTORY_SIZE;
        history[history_ptr].page = currentpoint;
        history[history_ptr].link = la->link_name;
        currentpoint = help_follow_link (currentpoint, la->link_name);
        selected_item = NULL;
    }
    else if (local.y < 0)
        move_backward (help_lines - 1);
    else if (local.y >= help_lines)
        move_forward (help_lines - 1);
    else if (local.y < help_lines / 2)
        move_backward (1);
    else
        move_forward (1);

    /* Show the new node */
    send_message (w->owner, NULL, MSG_DRAW, 0, NULL);

    return MOU_NORMAL;
}
예제 #7
0
파일: menu.c 프로젝트: BpArCuCTeMbI/mc
static int
menubar_event (Gpm_Event * event, void *data)
{
    WMenuBar *menubar = MENUBAR (data);
    Widget *w = WIDGET (data);
    gboolean was_active = TRUE;
    int left_x, right_x, bottom_y;
    menu_t *menu;
    Gpm_Event local;

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

    /* ignore unsupported events */
    if ((event->type & (GPM_UP | GPM_DOWN | GPM_DRAG)) == 0)
        return MOU_NORMAL;

    /* ignore wheel events if menu is inactive */
    if (!menubar->is_active && ((event->buttons & (GPM_B_MIDDLE | GPM_B_UP | GPM_B_DOWN)) != 0))
        return MOU_NORMAL;

    local = mouse_get_local (event, w);

    if (local.y == 1 && (local.type & GPM_UP) != 0)
        return MOU_NORMAL;

    if (!menubar->is_dropped)
    {
        if (local.y > 1)
        {
            /* mouse click below menubar -- close menu and send focus to widget under mouse */
            menubar_finish (menubar);
            return MOU_UNHANDLED;
        }

        menubar->previous_widget = dlg_get_current_widget_id (w->owner);
        menubar->is_active = TRUE;
        menubar->is_dropped = TRUE;
        was_active = FALSE;
    }

    /* Mouse operations on the menubar */
    if (local.y == 1 || !was_active)
    {
        /* wheel events on menubar */
        if ((local.buttons & GPM_B_UP) != 0)
            menubar_left (menubar);
        else if ((local.buttons & GPM_B_DOWN) != 0)
            menubar_right (menubar);
        else
        {
            const unsigned int len = g_list_length (menubar->menu);
            unsigned int new_selection = 0;

            while ((new_selection < len)
                   && (local.x > MENU (g_list_nth_data (menubar->menu, new_selection))->start_x))
                new_selection++;

            if (new_selection != 0)     /* Don't set the invalid value -1 */
                new_selection--;

            if (!was_active)
            {
                menubar->selected = new_selection;
                dlg_select_widget (menubar);
            }
            else
            {
                menubar_remove (menubar);
                menubar->selected = new_selection;
            }
            menubar_draw (menubar);
        }
        return MOU_NORMAL;
    }

    if (!menubar->is_dropped || (local.y < 2))
        return MOU_NORMAL;

    /* middle click -- everywhere */
    if (((local.buttons & GPM_B_MIDDLE) != 0) && ((local.type & GPM_DOWN) != 0))
    {
        menubar_execute (menubar);
        return MOU_NORMAL;
    }

    /* the mouse operation is on the menus or it is not */
    menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
    left_x = menu->start_x;
    right_x = left_x + menu->max_entry_len + 3;
    if (right_x > w->cols)
    {
        left_x = w->cols - menu->max_entry_len - 3;
        right_x = w->cols;
    }

    bottom_y = g_list_length (menu->entries) + 3;

    if ((local.x >= left_x) && (local.x <= right_x) && (local.y <= bottom_y))
    {
        int pos = local.y - 3;
        const menu_entry_t *entry = MENUENTRY (g_list_nth_data (menu->entries, pos));

        /* mouse wheel */
        if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0)
        {
            menubar_up (menubar);
            return MOU_NORMAL;
        }
        if ((local.buttons & GPM_B_DOWN) != 0 && (local.type & GPM_DOWN) != 0)
        {
            menubar_down (menubar);
            return MOU_NORMAL;
        }

        /* ignore events above and below dropped down menu */
        if ((pos < 0) || (pos >= bottom_y - 3))
            return MOU_NORMAL;

        if ((entry != NULL) && (entry->command != CK_IgnoreKey))
        {
            menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);
            menu->selected = pos;
            menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);

            if ((event->type & GPM_UP) != 0)
                menubar_execute (menubar);
        }
    }
    else if (((local.type & GPM_DOWN) != 0) && ((local.buttons & (GPM_B_UP | GPM_B_DOWN)) == 0))
    {
        /* use click not wheel to close menu */
        menubar_finish (menubar);
    }

    return MOU_NORMAL;
}
예제 #8
0
파일: mcviewer.c 프로젝트: CTU-OSP/mc
/** 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;
}
예제 #9
0
static int
edit_event (Gpm_Event * event, void *data)
{
    WEdit *edit = (WEdit *) data;
    Widget *w = WIDGET (data);
    Gpm_Event local;

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

    local = mouse_get_local (event, w);

    /* Unknown event type */
    if ((event->type & (GPM_DOWN | GPM_DRAG | GPM_UP)) == 0)
        return MOU_NORMAL;

    dlg_set_top_widget (w);

    edit_update_curs_row (edit);
    edit_update_curs_col (edit);

    if (edit->fullscreen || (local.buttons & GPM_B_LEFT) == 0 || (local.type & GPM_UP) != 0)
        edit->drag_state = MCEDIT_DRAG_NORMAL;
    else if (local.y == 1 && edit->drag_state != MCEDIT_DRAG_RESIZE)
    {
        /* click on the top line (move) */
        int dx = edit->fullscreen ? 0 : 2;

        if (local.x == w->cols - dx - 1)
        {
            send_message (w->owner, NULL, MSG_ACTION, CK_Close, NULL);
            return MOU_NORMAL;
        }

        if (local.x == w->cols - dx - 4)
        {
            edit_toggle_fullscreen (edit);
            return MOU_NORMAL;
        }

        if ((local.type & (GPM_DOWN | GPM_DRAG)) != 0)
        {
            /* move if not fullscreen */
            edit->drag_state_start = local.x;
            edit->drag_state = MCEDIT_DRAG_MOVE;
            edit->force |= REDRAW_COMPLETELY;
            edit_update_screen (edit);
        }
    }
    else if (!edit->fullscreen && local.y == w->lines && local.x == w->cols)
    {
        /* click on bottom-right corner (resize) */
        if ((local.type & (GPM_DOWN | GPM_DRAG)) != 0)
        {
            edit->drag_state = MCEDIT_DRAG_RESIZE;
            edit->force |= REDRAW_COMPLETELY;
            edit_update_screen (edit);
        }
    }

    if (edit->drag_state == MCEDIT_DRAG_NORMAL)
    {
        gboolean done = TRUE;

        /* Double click */
        if ((local.type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE))
        {
            edit_mark_current_word_cmd (edit);
            goto update;
        }
#if 0
        /* Triple click */
        if ((local.type & (GPM_TRIPLE | GPM_UP)) == (GPM_UP | GPM_TRIPLE))
        {
            edit_mark_current_line_cmd (edit);
            goto update;
        }
#endif
        /* Wheel events */
        if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0)
        {
            edit_move_up (edit, 2, 1);
            goto update;
        }
        if ((local.buttons & GPM_B_DOWN) != 0 && (local.type & GPM_DOWN) != 0)
        {
            edit_move_down (edit, 2, 1);
            goto update;
        }

        /* continue handle current event */
        goto cont;

        /* handle DRAG mouse event, don't use standard way to continue
         * event handling outside of widget */
        do
        {
            int c;

            c = tty_get_event (event, FALSE, TRUE);
            if (c == EV_NONE || c != EV_MOUSE)
                break;

            local = mouse_get_local (event, w);

          cont:
            /* A lone up mustn't do anything */
            if (edit->mark2 != -1 && (local.type & (GPM_UP | GPM_DRAG)) != 0)
                return MOU_NORMAL;

            if ((local.type & (GPM_DOWN | GPM_UP)) != 0)
                edit_push_key_press (edit);

            if (!edit->fullscreen)
                local.x--;
            if (!option_cursor_beyond_eol)
                edit->prev_col = local.x - edit->start_col - option_line_state_width - 1;
            else
            {
                long line_len;

                line_len = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0,
                                               edit_buffer_get_current_eol (&edit->buffer));

                if (local.x > line_len)
                {
                    edit->over_col =
                        local.x - line_len - edit->start_col - option_line_state_width - 1;
                    edit->prev_col = line_len;
                }
                else
                {
                    edit->over_col = 0;
                    edit->prev_col = local.x - option_line_state_width - edit->start_col - 1;
                }
            }

            if (!edit->fullscreen)
                local.y--;
            if (local.y > (edit->curs_row + 1))
                edit_move_down (edit, local.y - (edit->curs_row + 1), 0);
            else if (local.y < (edit->curs_row + 1))
                edit_move_up (edit, (edit->curs_row + 1) - local.y, 0);
            else
                edit_move_to_prev_col (edit, edit_buffer_get_current_bol (&edit->buffer));

            if ((local.type & GPM_DOWN) != 0)
            {
                edit_mark_cmd (edit, TRUE);     /* reset */
                edit->highlight = 0;
            }

            done = (local.type & GPM_DRAG) == 0;
            if (done)
                edit_mark_cmd (edit, FALSE);

          update:
            edit_find_bracket (edit);
            edit->force |= REDRAW_COMPLETELY;
            edit_update_curs_row (edit);
            edit_update_curs_col (edit);
            edit_update_screen (edit);
        }
        while (!edit->fullscreen && !done);
    }
    else
        while (edit->drag_state != MCEDIT_DRAG_NORMAL)
        {
            int c;
            int y;

            c = tty_get_event (event, FALSE, TRUE);
            y = event->y - 1;

            if (c == EV_NONE || c != EV_MOUSE)
            {
                /* redraw frame */
                edit->drag_state = MCEDIT_DRAG_NORMAL;
                edit->force |= REDRAW_COMPLETELY;
                edit_update_screen (edit);
            }
            else if (y == w->y && (event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_DOUBLE | GPM_UP))
            {
                /* double click on top line (toggle fullscreen) */
                edit_toggle_fullscreen (edit);
                edit->drag_state = MCEDIT_DRAG_NORMAL;
                edit->force |= REDRAW_COMPLETELY;
                edit_update_screen (edit);
            }
            else if ((event->type & (GPM_DRAG | GPM_DOWN)) == 0)
            {
                /* redraw frame */
                edit->drag_state = MCEDIT_DRAG_NORMAL;
                edit->force |= REDRAW_COMPLETELY;
                edit_update_screen (edit);
            }
            else if (!edit->fullscreen)
            {
                Widget *h = WIDGET (w->owner);

                if (edit->drag_state == MCEDIT_DRAG_MOVE)
                {
                    int x = event->x - 1;

                    y = max (y, h->y + 1);      /* status line */
                    y = min (y, h->y + h->lines - 2);   /* buttonbar */
                    x = max (x, h->x);
                    x = min (x, h->x + h->cols - 1);
                    /* don't use widget_set_size() here to avoid double draw  */
                    w->y = y;
                    w->x = x - edit->drag_state_start;
                    edit->force |= REDRAW_COMPLETELY;
                }
                else if (edit->drag_state == MCEDIT_DRAG_RESIZE)
                {
                    event->y = min (event->y, h->y + h->lines - 1);     /* buttonbar */
                    event->x = min (event->x, h->x + h->cols);
                    local = mouse_get_local (event, w);

                    /* don't use widget_set_size() here to avoid double draw  */
                    w->lines = max (WINDOW_MIN_LINES, local.y);
                    w->cols = max (WINDOW_MIN_COLS, local.x);
                    edit->force |= REDRAW_COMPLETELY;
                }

                dlg_redraw (w->owner);
            }
        }

    return MOU_NORMAL;
}