Ejemplo n.º 1
0
Archivo: chmod.c Proyecto: BrEacK/mc
static cb_ret_t
chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
{
    char buffer[BUF_TINY];
    int id;

    id = dlg_get_current_widget_id (h) - (chmod_but_num - (single_set ? 4 : 0)) - 1;

    switch (msg)
    {
    case DLG_ACTION:
        /* close dialog due to SIGINT (ctrl-g) */
        if (sender == NULL && parm == CK_Cancel)
            return MSG_NOT_HANDLED;

        /* handle checkboxes */
        if (id >= 0)
        {
            gboolean sender_is_checkbox = FALSE;
            unsigned int i;

            /* whether action was sent by checkbox? */
            for (i = 0; i < check_perm_num; i++)
                if (sender == (Widget *) check_perm[i].check)
                {
                    sender_is_checkbox = TRUE;
                    break;
                }

            if (sender_is_checkbox)
            {
                c_stat ^= check_perm[id].mode;
                g_snprintf (buffer, sizeof (buffer), "%o", (unsigned int) c_stat);
                label_set_text (statl, buffer);
                chmod_toggle_select (h, id);
                mode_change = TRUE;
                return MSG_HANDLED;
            }
        }

        return MSG_NOT_HANDLED;

    case DLG_KEY:
        if ((parm == 'T' || parm == 't' || parm == KEY_IC) && id > 0)
        {
            chmod_toggle_select (h, id);
            if (parm == KEY_IC)
                dlg_one_down (h);
            return MSG_HANDLED;
        }
        return MSG_NOT_HANDLED;

    case DLG_DRAW:
        chmod_refresh (h);
        return MSG_HANDLED;

    default:
        return default_dlg_callback (h, sender, msg, parm, data);
    }
}
Ejemplo n.º 2
0
static void
edit_drop_menu_cmd (WEdit * e, int which)
{
    WMenuBar *menubar;

    menubar = find_menubar (e->widget.owner);

    if (!menubar->is_active)
    {
        menubar->is_active = TRUE;
        menubar->is_dropped = (drop_menus != 0);
        if (which >= 0)
            menubar->selected = which;

        menubar->previous_widget = dlg_get_current_widget_id (e->widget.owner);
        dlg_select_widget (menubar);
    }
}
Ejemplo n.º 3
0
static cb_ret_t
chmod_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
{
    char buffer[BUF_TINY];
    int id = dlg_get_current_widget_id (h) - BUTTONS + single_set * 2 - 1;

    switch (msg)
    {
    case DLG_ACTION:
        if (id >= 0)
        {
            c_stat ^= check_perm[id].mode;
            g_snprintf (buffer, sizeof (buffer), "%o", (unsigned int) c_stat);
            label_set_text (statl, buffer);
            chmod_toggle_select (h, id);
            mode_change = 1;
        }
        return MSG_HANDLED;

    case DLG_KEY:
        if ((parm == 'T' || parm == 't' || parm == KEY_IC) && id > 0)
        {
            chmod_toggle_select (h, id);
            if (parm == KEY_IC)
                dlg_one_down (h);
            return MSG_HANDLED;
        }
        return MSG_NOT_HANDLED;

    case DLG_DRAW:
        chmod_refresh (h);
        return MSG_HANDLED;

    default:
        return default_dlg_callback (h, sender, msg, parm, data);
    }
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
Archivo: achown.c Proyecto: jskDr/mc
static cb_ret_t
advanced_chown_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WDialog *h = DIALOG (w);
    int i;
    int f_pos;
    unsigned long id;

    id = dlg_get_current_widget_id (h);

    for (i = 0; i < BUTTONS_PERM; i++)
        if (chown_advanced_but[i].id == id)
            break;

    f_pos = i;
    i = 0;

    switch (msg)
    {
    case MSG_DRAW:
        chown_refresh ();
        chown_info_update ();
        return MSG_HANDLED;

    case MSG_POST_KEY:
        if (f_pos < 3)
            b_setpos (f_pos);
        return MSG_HANDLED;

    case MSG_FOCUS:
        if (f_pos < 3)
        {
            if ((flag_pos / 3) != f_pos)
                flag_pos = f_pos * 3;
            b_setpos (f_pos);
        }
        else if (f_pos < BUTTONS_PERM)
            flag_pos = f_pos + 6;
        return MSG_HANDLED;

    case MSG_KEY:
        switch (parm)
        {
        case XCTRL ('b'):
        case KEY_LEFT:
            if (f_pos < BUTTONS_PERM)
                return (dec_flag_pos (f_pos));
            break;

        case XCTRL ('f'):
        case KEY_RIGHT:
            if (f_pos < BUTTONS_PERM)
                return (inc_flag_pos (f_pos));
            break;

        case ' ':
            if (f_pos < 3)
                return MSG_HANDLED;
            break;

        case '\n':
        case KEY_ENTER:
            if (f_pos <= 2 || f_pos >= BUTTONS_PERM)
                break;
            do_enter_key (h, f_pos);
            return MSG_HANDLED;

        case ALT ('x'):
            i++;

        case ALT ('w'):
            i++;

        case ALT ('r'):
            parm = i + 3;
            for (i = 0; i < 3; i++)
                ch_flags[i * 3 + parm - 3] = (x_toggle & (1 << parm)) ? '-' : '+';
            x_toggle ^= (1 << parm);
            update_mode (h);
            dlg_broadcast_msg (h, MSG_DRAW);
            send_message (h->current->data, NULL, MSG_FOCUS, 0, NULL);
            break;

        case XCTRL ('x'):
            i++;

        case XCTRL ('w'):
            i++;

        case XCTRL ('r'):
            parm = i;
            for (i = 0; i < 3; i++)
                ch_flags[i * 3 + parm] = (x_toggle & (1 << parm)) ? '-' : '+';
            x_toggle ^= (1 << parm);
            update_mode (h);
            dlg_broadcast_msg (h, MSG_DRAW);
            send_message (h->current->data, NULL, MSG_FOCUS, 0, NULL);
            break;

        case 'x':
            i++;

        case 'w':
            i++;

        case 'r':
            if (f_pos > 2)
                break;
            flag_pos = f_pos * 3 + i;   /* (strchr(ch_perm,parm)-ch_perm); */
            if (BUTTON (h->current->data)->text.start[(flag_pos % 3)] == '-')
                ch_flags[flag_pos] = '+';
            else
                ch_flags[flag_pos] = '-';
            update_mode (h);
            break;

        case '4':
            i++;

        case '2':
            i++;

        case '1':
            if (f_pos <= 2)
            {
                flag_pos = i + f_pos * 3;
                ch_flags[flag_pos] = '=';
                update_mode (h);
            }
            break;

        case '-':
            if (f_pos > 2)
                break;

        case '*':
            if (parm == '*')
                parm = '=';

        case '=':
        case '+':
            if (f_pos <= 4)
            {
                ch_flags[flag_pos] = parm;
                update_mode (h);
                send_message (h, sender, MSG_KEY, KEY_RIGHT, NULL);
                if (flag_pos > 8 || (flag_pos % 3) == 0)
                    dlg_one_down (h);
            }
            break;

        default:
            break;
        }
        return MSG_NOT_HANDLED;

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