Beispiel #1
0
static void
menubar_first (WMenuBar * menubar)
{
    menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));

    if (menu->selected == 0)
        return;

    menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);

    menu->selected = 0;

    while (TRUE)
    {
        menu_entry_t *entry;

        entry = MENUENTRY (g_list_nth_data (menu->entries, menu->selected));

        if ((entry == NULL) || (entry->command == CK_IgnoreKey))
            menu->selected++;
        else
            break;
    }

    menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
}
Beispiel #2
0
static void
menubar_down (WMenuBar * menubar)
{
    menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
    const unsigned int len = g_list_length (menu->entries);
    menu_entry_t *entry;

    menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);

    do
    {
        menu->selected = (menu->selected + 1) % len;
        entry = MENUENTRY (g_list_nth_data (menu->entries, menu->selected));
    }
    while ((entry == NULL) || (entry->command == CK_IgnoreKey));

    menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
}
Beispiel #3
0
Datei: menu.c Projekt: ryanlee/mc
static void
menubar_up (WMenuBar * menubar)
{
    Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
    const unsigned int len = g_list_length (menu->entries);
    menu_entry_t *entry;

    menubar_paint_idx (menubar, menu->selected, MENU_ENTRY_COLOR);

    do
    {
        if (menu->selected == 0)
            menu->selected = len - 1;
        else
            menu->selected--;
        entry = (menu_entry_t *) g_list_nth_data (menu->entries, menu->selected);
    }
    while ((entry == NULL) || (entry->command == CK_IgnoreKey));

    menubar_paint_idx (menubar, menu->selected, MENU_SELECTED_COLOR);
}
Beispiel #4
0
static void
menubar_draw_drop (WMenuBar * menubar)
{
    Widget *w = WIDGET (menubar);
    const menu_t *menu = MENU (g_list_nth_data (menubar->menu, menubar->selected));
    const unsigned int count = g_list_length (menu->entries);
    int column = menu->start_x - 1;
    unsigned int i;

    if (column + menu->max_entry_len + 5 > (gsize) w->cols)
        column = w->cols - menu->max_entry_len - 5;

    tty_setcolor (MENU_ENTRY_COLOR);
    tty_draw_box (w->y + 1, w->x + column, count + 2, menu->max_entry_len + 5, FALSE);

    for (i = 0; i < count; i++)
        menubar_paint_idx (menubar, i,
                           i == menu->selected ? MENU_SELECTED_COLOR : MENU_ENTRY_COLOR);
}
Beispiel #5
0
Datei: menu.c Projekt: ryanlee/mc
static void
menubar_draw_drop (WMenuBar * menubar)
{
    const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
    const unsigned int count = g_list_length (menu->entries);
    int column = menu->start_x - 1;
    unsigned int i;

    if (column + menu->max_entry_len + 5 > (gsize) menubar->widget.cols)
        column = menubar->widget.cols - menu->max_entry_len - 5;

    tty_setcolor (MENU_ENTRY_COLOR);
    draw_box (menubar->widget.owner,
              menubar->widget.y + 1, menubar->widget.x + column,
              count + 2, menu->max_entry_len + 5, FALSE);

    for (i = 0; i < count; i++)
        menubar_paint_idx (menubar, i,
                           i == menu->selected ? MENU_SELECTED_COLOR : MENU_ENTRY_COLOR);
}
Beispiel #6
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;
}