Exemplo n.º 1
0
static int
dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
{
    GList *item;
    GList *starting_widget = h->current;
    Gpm_Event new_event;
    int x = event->x;
    int y = event->y;

    /* close the dialog by mouse click out of dialog area */
    if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
        && !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines)))
    {
        h->ret_value = B_CANCEL;
        dlg_stop (h);
        return MOU_NORMAL;
    }

    item = starting_widget;
    do
    {
        Widget *widget;

        widget = (Widget *) item->data;
        item = dlg_widget_next (h, item);

        if (((widget->options & W_DISABLED) == 0)
            && (x > widget->x) && (x <= widget->x + widget->cols)
            && (y > widget->y) && (y <= widget->y + widget->lines))
        {
            new_event = *event;
            new_event.x -= widget->x;
            new_event.y -= widget->y;

            if (widget->mouse != NULL)
                return widget->mouse (&new_event, widget);
        }
    }
    while (item != starting_widget);

    return MOU_NORMAL;
}
Exemplo n.º 2
0
static void
listbox_do_action (WListbox * l)
{
    int action;

    if (listbox_is_empty (l))
        return;

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

    if (action == LISTBOX_DONE)
    {
        WDialog *h = WIDGET (l)->owner;

        h->ret_value = B_ENTER;
        dlg_stop (h);
    }
}
Exemplo n.º 3
0
static cb_ret_t
tree_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
{
    switch (msg)
    {
    case DLG_POST_KEY:
        /* The enter key will be processed by the tree widget */
        if (parm == '\n')
        {
            h->ret_value = B_ENTER;
            dlg_stop (h);
        }
        return MSG_HANDLED;

    case DLG_ACTION:
        /* command from buttonbar */
        return send_message ((Widget *) find_tree (h), WIDGET_COMMAND, parm);

    default:
        return default_dlg_callback (h, sender, msg, parm, data);
    }
}
Exemplo n.º 4
0
Arquivo: achown.c Projeto: CTU-OSP/mc
static cb_ret_t
chl_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    switch (msg)
    {
    case MSG_KEY:
        switch (parm)
        {
        case KEY_LEFT:
        case KEY_RIGHT:
            {
                WDialog *h = DIALOG (w);

                h->ret_value = parm;
                dlg_stop (h);
            }
        }

    default:
        return dlg_default_callback (w, sender, msg, parm, data);
    }
}
Exemplo n.º 5
0
static cb_ret_t
dlg_execute_cmd (WDialog * h, unsigned long command)
{
    cb_ret_t ret = MSG_HANDLED;
    switch (command)
    {
    case CK_Ok:
        h->ret_value = B_ENTER;
        dlg_stop (h);
        break;
    case CK_Cancel:
        h->ret_value = B_CANCEL;
        dlg_stop (h);
        break;

    case CK_Up:
    case CK_Left:
        dlg_one_up (h);
        break;
    case CK_Down:
    case CK_Right:
        dlg_one_down (h);
        break;

    case CK_Help:
        {
            ev_help_t event_data = { NULL, h->help_ctx };
            mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
        }
        break;

    case CK_Suspend:
        mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
        refresh_cmd ();
        break;
    case CK_Refresh:
        refresh_cmd ();
        break;

    case CK_ScreenList:
        if (!h->modal)
            dialog_switch_list ();
        else
            ret = MSG_NOT_HANDLED;
        break;
    case CK_ScreenNext:
        if (!h->modal)
            dialog_switch_next ();
        else
            ret = MSG_NOT_HANDLED;
        break;
    case CK_ScreenPrev:
        if (!h->modal)
            dialog_switch_prev ();
        else
            ret = MSG_NOT_HANDLED;
        break;

    default:
        ret = MSG_NOT_HANDLED;
    }

    return ret;
}
Exemplo n.º 6
0
static cb_ret_t
edit_dialog_command_execute (WDialog * h, long command)
{
    Widget *wh = WIDGET (h);
    cb_ret_t ret = MSG_HANDLED;

    switch (command)
    {
    case CK_EditNew:
        edit_add_window (h, wh->y + 1, wh->x, wh->lines - 2, wh->cols, NULL, 0);
        break;
    case CK_EditFile:
        edit_load_cmd (h);
        break;
    case CK_EditSyntaxFile:
        edit_load_syntax_file (h);
        break;
    case CK_EditUserMenu:
        edit_load_menu_file (h);
        break;
    case CK_Close:
        /* if there are no opened files anymore, close MC editor */
        if (edit_widget_is_editor (CONST_WIDGET (h->current->data)) &&
            edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL)
            dlg_stop (h);
        break;
    case CK_Help:
        edit_help ();
        /* edit->force |= REDRAW_COMPLETELY; */
        break;
    case CK_Menu:
        edit_menu_cmd (h);
        break;
    case CK_Quit:
    case CK_Cancel:
        /* don't close editor due to SIGINT, but stop move/resize window */
        {
            Widget *w = WIDGET (h->current->data);

            if (edit_widget_is_editor (w) && ((WEdit *) w)->drag_state != MCEDIT_DRAG_NONE)
                edit_restore_size ((WEdit *) w);
            else if (command == CK_Quit)
                dlg_stop (h);
        }
        break;
    case CK_About:
        edit_about ();
        break;
    case CK_SyntaxOnOff:
        edit_syntax_onoff_cmd (h);
        break;
    case CK_ShowTabTws:
        edit_show_tabs_tws_cmd (h);
        break;
    case CK_ShowMargin:
        edit_show_margin_cmd (h);
        break;
    case CK_ShowNumbers:
        edit_show_numbers_cmd (h);
        break;
    case CK_Refresh:
        edit_refresh_cmd ();
        break;
    case CK_Shell:
        view_other_cmd ();
        break;
    case CK_LearnKeys:
        learn_keys ();
        break;
    case CK_WindowMove:
    case CK_WindowResize:
        if (edit_widget_is_editor (CONST_WIDGET (h->current->data)))
            edit_handle_move_resize ((WEdit *) h->current->data, command);
        break;
    case CK_WindowList:
        edit_window_list (h);
        break;
    case CK_WindowNext:
        dlg_select_next_widget (h);
        break;
    case CK_WindowPrev:
        dlg_select_prev_widget (h);
        break;
    case CK_Options:
        edit_options_dialog (h);
        break;
    case CK_OptionsSaveMode:
        edit_save_mode_cmd ();
        break;
    case CK_SaveSetup:
        save_setup_cmd ();
        break;
    default:
        ret = MSG_NOT_HANDLED;
        break;
    }

    return ret;
}
Exemplo n.º 7
0
static gboolean
learn_check_key (int c)
{
    int i;

    for (i = 0; i < learn_total; i++)
    {
        if (key_name_conv_tab[i].code != c || learnkeys[i].ok)
            continue;

        widget_select (learnkeys[i].button);
        /* TRANSLATORS: This label appears near learned keys.  Keep it short.  */
        label_set_text (LABEL (learnkeys[i].label), _("OK"));
        learnkeys[i].ok = TRUE;
        learnok++;
        if (learnok >= learn_total)
        {
            learn_dlg->ret_value = B_CANCEL;
            if (learnchanged)
            {
                if (query_dialog (learn_title,
                                  _
                                  ("It seems that all your keys already\n"
                                   "work fine. That's great."), D_ERROR, 2,
                                  _("&Save"), _("&Discard")) == 0)
                    learn_dlg->ret_value = B_ENTER;
            }
            else
            {
                message (D_ERROR, learn_title, "%s",
                         _
                         ("Great! You have a complete terminal database!\n"
                          "All your keys work well."));
            }
            dlg_stop (learn_dlg);
        }
        return TRUE;
    }

    switch (c)
    {
    case KEY_LEFT:
    case 'h':
        return learn_move (FALSE);
    case KEY_RIGHT:
    case 'l':
        return learn_move (TRUE);
    case 'j':
        dlg_select_next_widget (learn_dlg);
        return TRUE;
    case 'k':
        dlg_select_prev_widget (learn_dlg);
        return TRUE;
    default:
        break;
    }

    /* Prevent from disappearing if a non-defined sequence is pressed
       and contains a button hotkey.  Only recognize hotkeys with ALT.  */
    return (c < 255 && g_ascii_isalnum (c));
}
Exemplo n.º 8
0
static cb_ret_t
display_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
{
    switch (msg)
    {
    case DLG_KEY:
        if (parm == '\n')
        {
            if (dlg_widget_active (display_radio))
            {
                input_assign_text (display_mini_status, displays_status[display_radio->sel]);
                dlg_stop (h);
                return MSG_HANDLED;
            }

            if (dlg_widget_active (display_user_format))
            {
                h->ret_value = B_USER + 6;
                dlg_stop (h);
                return MSG_HANDLED;
            }

            if (dlg_widget_active (display_mini_status))
            {
                h->ret_value = B_USER + 7;
                dlg_stop (h);
                return MSG_HANDLED;
            }
        }

        if ((g_ascii_tolower (parm) == display_user_hotkey)
            && dlg_widget_active (display_user_format) && dlg_widget_active (display_mini_status))
        {
            display_radio->pos = display_radio->sel = 3;
            dlg_select_widget (display_radio);  /* force redraw */
            h->callback (h, (Widget *) display_radio, DLG_ACTION, 0, NULL);
            return MSG_HANDLED;
        }
        return MSG_NOT_HANDLED;

    case DLG_ACTION:
        if (sender == (Widget *) display_radio)
        {
            if (!(display_check_status->state & C_BOOL))
                input_assign_text (display_mini_status, displays_status[display_radio->sel]);
            input_update (display_mini_status, FALSE);
            input_update (display_user_format, FALSE);
            widget_disable (display_user_format->widget, display_radio->sel != 3);
            return MSG_HANDLED;
        }

        if (sender == (Widget *) display_check_status)
        {
            if (display_check_status->state & C_BOOL)
            {
                widget_disable (display_mini_status->widget, FALSE);
                input_assign_text (display_mini_status, displays_status[3]);
            }
            else
            {
                widget_disable (display_mini_status->widget, TRUE);
                input_assign_text (display_mini_status, displays_status[display_radio->sel]);
            }
            input_update (display_mini_status, FALSE);
            return MSG_HANDLED;
        }

        return MSG_NOT_HANDLED;

    default:
        return default_dlg_callback (h, sender, msg, parm, data);
    }
}
Exemplo n.º 9
0
static cb_ret_t
dlg_execute_cmd (WDialog * h, long command)
{
    cb_ret_t ret = MSG_HANDLED;

    if (send_message (h, NULL, MSG_ACTION, command, NULL) == MSG_HANDLED)
        return MSG_HANDLED;

    switch (command)
    {
    case CK_Ok:
        h->ret_value = B_ENTER;
        dlg_stop (h);
        break;
    case CK_Cancel:
        h->ret_value = B_CANCEL;
        dlg_stop (h);
        break;

    case CK_Up:
    case CK_Left:
        dlg_select_prev_widget (h);
        break;
    case CK_Down:
    case CK_Right:
        dlg_select_next_widget (h);
        break;

    case CK_Help:
        {
            ev_help_t event_data = { NULL, h->help_ctx };
            mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
        }
        break;

    case CK_Suspend:
        mc_event_raise (MCEVENT_GROUP_CORE, "suspend", NULL);
        refresh_cmd ();
        break;
    case CK_Refresh:
        refresh_cmd ();
        break;

    case CK_ScreenList:
        if (!widget_get_state (WIDGET (h), WST_MODAL))
            dialog_switch_list ();
        else
            ret = MSG_NOT_HANDLED;
        break;
    case CK_ScreenNext:
        if (!widget_get_state (WIDGET (h), WST_MODAL))
            dialog_switch_next ();
        else
            ret = MSG_NOT_HANDLED;
        break;
    case CK_ScreenPrev:
        if (!widget_get_state (WIDGET (h), WST_MODAL))
            dialog_switch_prev ();
        else
            ret = MSG_NOT_HANDLED;
        break;

    default:
        ret = MSG_NOT_HANDLED;
    }

    return ret;
}
Exemplo n.º 10
0
static cb_ret_t
listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WListbox *l = LISTBOX (w);
    WDialog *h = w->owner;
    cb_ret_t ret_code;

    switch (msg)
    {
    case MSG_INIT:
        return MSG_HANDLED;

    case MSG_HOTKEY:
        {
            int pos, action;

            pos = listbox_check_hotkey (l, parm);
            if (pos < 0)
                return MSG_NOT_HANDLED;

            listbox_select_entry (l, pos);
            send_message (h, w, MSG_ACTION, l->pos, NULL);

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

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

            return MSG_HANDLED;
        }

    case MSG_KEY:
        ret_code = listbox_key (l, parm);
        if (ret_code != MSG_NOT_HANDLED)
        {
            listbox_draw (l, TRUE);
            send_message (h, w, MSG_ACTION, l->pos, NULL);
        }
        return ret_code;

    case MSG_ACTION:
        return listbox_execute_cmd (l, parm);

    case MSG_CURSOR:
        widget_move (l, l->cursor_y, 0);
        send_message (h, w, MSG_ACTION, l->pos, NULL);
        return MSG_HANDLED;

    case MSG_FOCUS:
    case MSG_UNFOCUS:
    case MSG_DRAW:
        listbox_draw (l, msg != MSG_UNFOCUS);
        return MSG_HANDLED;

    case MSG_DESTROY:
        listbox_destroy (l);
        return MSG_HANDLED;

    case MSG_RESIZE:
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Exemplo n.º 11
0
static cb_ret_t
tree_execute_cmd (WTree * tree, long command)
{
    cb_ret_t res = MSG_HANDLED;

    if (command != CK_Search)
        tree->searching = 0;

    switch (command)
    {
    case CK_Help:
        {
            ev_help_t event_data = { NULL, "[Directory Tree]" };
            mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
        }
        break;
    case CK_Forget:
        tree_forget (tree);
        break;
    case CK_ToggleNavigation:
        tree_toggle_navig (tree);
        break;
    case CK_Copy:
        tree_copy (tree, "");
        break;
    case CK_Move:
        tree_move (tree, "");
        break;
    case CK_Up:
        tree_move_up (tree);
        break;
    case CK_Down:
        tree_move_down (tree);
        break;
    case CK_Top:
        tree_move_home (tree);
        break;
    case CK_Bottom:
        tree_move_end (tree);
        break;
    case CK_PageUp:
        tree_move_pgup (tree);
        break;
    case CK_PageDown:
        tree_move_pgdn (tree);
        break;
    case CK_Enter:
        tree_chdir_sel (tree);
        break;
    case CK_Reread:
        tree_rescan (tree);
        break;
    case CK_Search:
        tree_start_search (tree);
        break;
    case CK_Delete:
        tree_rmdir (tree);
        break;
    case CK_Quit:
        if (!tree->is_panel)
            dlg_stop (WIDGET (tree)->owner);
        return res;
    default:
        res = MSG_NOT_HANDLED;
    }

    show_tree (tree);

    return res;
}
Exemplo n.º 12
0
static cb_ret_t
panel_listing_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WDialog *h = DIALOG (w);

    switch (msg)
    {
    case MSG_KEY:
        if (parm == '\n')
        {
            Widget *wi;

            wi = dlg_find_by_id (h, panel_listing_types_id);
            if (widget_is_active (wi))
            {
                WInput *in;

                in = INPUT (dlg_find_by_id (h, mini_user_format_id));
                input_assign_text (in, status_format[RADIO (wi)->sel]);
                dlg_stop (h);
                return MSG_HANDLED;
            }

            wi = dlg_find_by_id (h, panel_user_format_id);
            if (widget_is_active (wi))
            {
                h->ret_value = B_USER + 6;
                dlg_stop (h);
                return MSG_HANDLED;
            }

            wi = dlg_find_by_id (h, mini_user_format_id);
            if (widget_is_active (wi))
            {
                h->ret_value = B_USER + 7;
                dlg_stop (h);
                return MSG_HANDLED;
            }
        }

        if (g_ascii_tolower (parm) == listing_user_hotkey)
        {
            Widget *wi;

            wi = dlg_find_by_id (h, panel_user_format_id);
            if (widget_is_active (wi))
            {
                wi = dlg_find_by_id (h, mini_user_format_id);
                if (widget_is_active (wi))
                {
                    WRadio *r;

                    r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
                    r->pos = r->sel = panel_listing_user_idx;
                    dlg_select_widget (WIDGET (r));     /* force redraw */
                    send_message (h, r, MSG_ACTION, 0, NULL);
                    return MSG_HANDLED;
                }
            }
        }
        return MSG_NOT_HANDLED;

    case MSG_ACTION:
        if (sender != NULL && sender->id == panel_listing_types_id)
        {
            WCheck *ch;
            WInput *in1, *in2, *in3;

            in1 = INPUT (dlg_find_by_id (h, panel_user_format_id));
            in2 = INPUT (dlg_find_by_id (h, panel_brief_cols_id));
            ch = CHECK (dlg_find_by_id (h, mini_user_status_id));
            in3 = INPUT (dlg_find_by_id (h, mini_user_format_id));

            if (!(ch->state & C_BOOL))
                input_assign_text (in3, status_format[RADIO (sender)->sel]);
            input_update (in1, FALSE);
            input_update (in2, FALSE);
            input_update (in3, FALSE);
            widget_disable (WIDGET (in1), RADIO (sender)->sel != panel_listing_user_idx);
            widget_disable (WIDGET (in2), RADIO (sender)->sel != panel_listing_brief_idx);
            return MSG_HANDLED;
        }

        if (sender != NULL && sender->id == mini_user_status_id)
        {
            WInput *in;

            in = INPUT (dlg_find_by_id (h, mini_user_format_id));

            if (CHECK (sender)->state & C_BOOL)
            {
                widget_disable (WIDGET (in), FALSE);
                input_assign_text (in, status_format[3]);
            }
            else
            {
                WRadio *r;

                r = RADIO (dlg_find_by_id (h, panel_listing_types_id));
                widget_disable (WIDGET (in), TRUE);
                input_assign_text (in, status_format[r->sel]);
            }
            /* input_update (in, FALSE); */
            return MSG_HANDLED;
        }

        return MSG_NOT_HANDLED;

    default:
        return dlg_default_callback (w, sender, msg, parm, data);
    }
}
Exemplo n.º 13
0
static cb_ret_t
query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *data)
{
    static char buff[MB_LEN_MAX] = "";
    static int bl = 0;

    switch (msg)
    {
    case DLG_KEY:
        switch (parm)
        {
        case KEY_LEFT:
        case KEY_RIGHT:
            bl = 0;
            h->ret_value = 0;
            dlg_stop (h);
            return MSG_HANDLED;

        case KEY_BACKSPACE:
            bl = 0;
            /* exit from completion list if input line is empty */
            if (end == 0)
            {
                h->ret_value = 0;
                dlg_stop (h);
            }
            /* Refill the list box and start again */
            else if (end == min_end)
            {
                end = str_get_prev_char (&input->buffer[end]) - input->buffer;
                input_handle_char (input, parm);
                h->ret_value = B_USER;
                dlg_stop (h);
                return MSG_HANDLED;
            }
            else
            {
                int new_end;
                int i;
                GList *e;

                new_end = str_get_prev_char (&input->buffer[end]) - input->buffer;

                for (i = 0, e = ((WListbox *) h->current->data)->list;
                     e != NULL; i++, e = g_list_next (e))
                {
                    WLEntry *le = (WLEntry *) e->data;

                    if (strncmp (input->buffer + start, le->text, new_end - start) == 0)
                    {
                        listbox_select_entry ((WListbox *) h->current->data, i);
                        end = new_end;
                        input_handle_char (input, parm);
                        send_message ((Widget *) h->current->data, WIDGET_DRAW, 0);
                        break;
                    }
                }
            }
            return MSG_HANDLED;

        default:
            if (parm < 32 || parm > 255)
            {
                bl = 0;
                if (input_key_is_in_map (input, parm) != 2)
                    return MSG_NOT_HANDLED;

                if (end == min_end)
                    return MSG_HANDLED;

                /* This means we want to refill the list box and start again */
                h->ret_value = B_USER;
                dlg_stop (h);
                return MSG_HANDLED;
            }
            else
            {
                GList *e;
                int i;
                int need_redraw = 0;
                int low = 4096;
                char *last_text = NULL;

                buff[bl++] = (char) parm;
                buff[bl] = '\0';
                switch (str_is_valid_char (buff, bl))
                {
                case -1:
                    bl = 0;
                    /* fallthrough */
                case -2:
                    return MSG_HANDLED;
                }

                for (i = 0, e = ((WListbox *) h->current->data)->list;
                     e != NULL; i++, e = g_list_next (e))
                {
                    WLEntry *le = (WLEntry *) e->data;

                    if (strncmp (input->buffer + start, le->text, end - start) == 0
                        && strncmp (&le->text[end - start], buff, bl) == 0)
                    {
                        if (need_redraw == 0)
                        {
                            need_redraw = 1;
                            listbox_select_entry ((WListbox *) h->current->data, i);
                            last_text = le->text;
                        }
                        else
                        {
                            char *si, *sl;
                            int si_num = 0;
                            int sl_num = 0;

                            /* count symbols between start and end */
                            for (si = le->text + start; si < le->text + end;
                                 str_next_char (&si), si_num++)
                                ;
                            for (sl = last_text + start; sl < last_text + end;
                                 str_next_char (&sl), sl_num++)
                                ;

                            /* pointers to next symbols */
                            si = &le->text[str_offset_to_pos (le->text, ++si_num)];
                            sl = &last_text[str_offset_to_pos (last_text, ++sl_num)];

                            while (si[0] != '\0' && sl[0] != '\0')
                            {
                                char *nexti, *nextl;

                                nexti = str_get_next_char (si);
                                nextl = str_get_next_char (sl);

                                if (nexti - si != nextl - sl || strncmp (si, sl, nexti - si) != 0)
                                    break;

                                si = nexti;
                                sl = nextl;

                                si_num++;
                            }

                            last_text = le->text;

                            si = &last_text[str_offset_to_pos (last_text, si_num)];
                            if (low > si - last_text)
                                low = si - last_text;

                            need_redraw = 2;
                        }
                    }
                }

                if (need_redraw == 2)
                {
                    insert_text (input, last_text, low);
                    send_message ((Widget *) h->current->data, WIDGET_DRAW, 0);
                }
                else if (need_redraw == 1)
                {
                    h->ret_value = B_ENTER;
                    dlg_stop (h);
                }
                bl = 0;
            }
            return MSG_HANDLED;
        }
        break;

    default:
        return default_dlg_callback (h, sender, msg, parm, data);
    }
}
Exemplo n.º 14
0
static void
view_quit_cmd (WDiff *view)
{
    dlg_stop(view->widget.parent);
}
Exemplo n.º 15
0
Arquivo: button.c Projeto: artzub/mc
static cb_ret_t
button_callback (Widget * w, widget_msg_t msg, int parm)
{
    WButton *b = (WButton *) w;
    int stop = 0;
    int off = 0;
    Dlg_head *h = b->widget.owner;

    switch (msg)
    {
    case WIDGET_HOTKEY:
        /*
         * Don't let the default button steal Enter from the current
         * button.  This is a workaround for the flawed event model
         * when hotkeys are sent to all widgets before the key is
         * handled by the current widget.
         */
        if (parm == '\n' && (Widget *) h->current->data == &b->widget)
        {
            button_callback (w, WIDGET_KEY, ' ');
            return MSG_HANDLED;
        }

        if (parm == '\n' && b->flags == DEFPUSH_BUTTON)
        {
            button_callback (w, WIDGET_KEY, ' ');
            return MSG_HANDLED;
        }

        if (b->text.hotkey != NULL &&
            g_ascii_tolower ((gchar) b->text.hotkey[0]) == parm)
        {
            button_callback (w, WIDGET_KEY, ' ');
            return MSG_HANDLED;
        }
        return MSG_NOT_HANDLED;

    case WIDGET_KEY:
        if (parm != ' ' && parm != '\n')
            return MSG_NOT_HANDLED;

        if (b->callback != NULL)
            stop = b->callback (b, b->action);
        if (b->callback == NULL || stop != 0)
        {
            h->ret_value = b->action;
            dlg_stop (h);
        }
        return MSG_HANDLED;

    case WIDGET_CURSOR:
        switch (b->flags)
        {
        case DEFPUSH_BUTTON:
            off = 3;
            break;
        case NORMAL_BUTTON:
            off = 2;
            break;
        case NARROW_BUTTON:
            off = 1;
            break;
        case HIDDEN_BUTTON:
        default:
            off = 0;
            break;
        }
        widget_move (&b->widget, 0, b->hotpos + off);
        return MSG_HANDLED;

    case WIDGET_UNFOCUS:
    case WIDGET_FOCUS:
    case WIDGET_DRAW:
        if (msg == WIDGET_UNFOCUS)
            b->selected = FALSE;
        else if (msg == WIDGET_FOCUS)
            b->selected = TRUE;

        widget_selectcolor (w, b->selected, FALSE);
        widget_move (w, 0, 0);

        switch (b->flags)
        {
        case DEFPUSH_BUTTON:
            tty_print_string ("[< ");
            break;
        case NORMAL_BUTTON:
            tty_print_string ("[ ");
            break;
        case NARROW_BUTTON:
            tty_print_string ("[");
            break;
        case HIDDEN_BUTTON:
        default:
            return MSG_HANDLED;
        }

        hotkey_draw (w, b->text, b->selected);

        switch (b->flags)
        {
        case DEFPUSH_BUTTON:
            tty_print_string (" >]");
            break;
        case NORMAL_BUTTON:
            tty_print_string (" ]");
            break;
        case NARROW_BUTTON:
            tty_print_string ("]");
            break;
        default:
            break;
        }
        return MSG_HANDLED;

    case WIDGET_DESTROY:
        release_hotkey (b->text);
        return MSG_HANDLED;

    default:
        return default_proc (msg, parm);
    }
}
Exemplo n.º 16
0
static cb_ret_t
help_execute_cmd (unsigned long command)
{
    cb_ret_t ret = MSG_HANDLED;

    switch (command)
    {
    case CK_Help:
        help_help (whelp);
        break;
    case CK_Index:
        help_index (whelp);
        break;
    case CK_Back:
        help_back (whelp);
        break;
    case CK_Up:
        help_prev_link (TRUE);
        break;
    case CK_Down:
        help_next_link (TRUE);
        break;
    case CK_PageDown:
        move_forward (help_lines - 1);
        break;
    case CK_PageUp:
        move_backward (help_lines - 1);
        break;
    case CK_HalfPageDown:
        move_forward (help_lines / 2);
        break;
    case CK_HalfPageUp:
        move_backward (help_lines / 2);
        break;
    case CK_Top:
        move_to_top ();
        break;
    case CK_Bottom:
        move_to_bottom ();
        break;
    case CK_Enter:
        help_select_link ();
        break;
    case CK_LinkNext:
        help_next_link (FALSE);
        break;
    case CK_LinkPrev:
        help_prev_link (FALSE);
        break;
    case CK_NodeNext:
        help_next_node ();
        break;
    case CK_NodePrev:
        help_prev_node ();
        break;
    case CK_Quit:
        dlg_stop (whelp);
        break;
    default:
        ret = MSG_NOT_HANDLED;
    }

    return ret;
}
Exemplo n.º 17
0
static cb_ret_t
query_callback (Dlg_head *h, dlg_msg_t msg, int parm)
{
    switch (msg) {
    case DLG_KEY:
	switch (parm) {
	case KEY_LEFT:
	case KEY_RIGHT:
	    h->ret_value = 0;
	    dlg_stop (h);
	    return 1;

	case KEY_BACKSPACE:
	    if (end == min_end) {
		h->ret_value = 0;
		dlg_stop (h);
		return 1;
	    } else {
		WLEntry *e, *e1;

		e1 = e = ((WListbox *) (h->current))->list;
		do {
		    if (!strncmp
			(input->buffer + start, e1->text,
			 end - start - 1)) {
			listbox_select_entry ((WListbox *) (h->current),
					      e1);
			handle_char (input, parm);
			end--;
			send_message (h->current, WIDGET_DRAW, 0);
			break;
		    }
		    e1 = e1->next;
		} while (e != e1);
	    }
	    return 1;

	default:
	    if (parm > 0xff || !is_printable (parm)) {
		if (is_in_input_map (input, parm) == 2) {
		    if (end == min_end)
			return 1;
		    h->ret_value = B_USER;	/* This means we want to refill the
						   list box and start again */
		    dlg_stop (h);
		    return 1;
		} else
		    return 0;
	    } else {
		WLEntry *e, *e1;
		int need_redraw = 0;
		int low = 4096;
		char *last_text = NULL;

		e1 = e = ((WListbox *) (h->current))->list;
		do {
		    if (!strncmp
			(input->buffer + start, e1->text, end - start)) {
			if (e1->text[end - start] == parm) {
			    if (need_redraw) {
				register int c1, c2, si;

				for (si = end - start + 1;
				     (c1 = last_text[si])
				     && (c2 = e1->text[si]); si++)
				    if (c1 != c2)
					break;
				if (low > si)
				    low = si;
				last_text = e1->text;
				need_redraw = 2;
			    } else {
				need_redraw = 1;
				listbox_select_entry ((WListbox *) (h->
								    current),
						      e1);
				last_text = e1->text;
			    }
			}
		    }
		    e1 = e1->next;
		} while (e != e1);
		if (need_redraw == 2) {
		    insert_text (input, last_text, low);
		    send_message (h->current, WIDGET_DRAW, 0);
		} else if (need_redraw == 1) {
		    h->ret_value = B_ENTER;
		    dlg_stop (h);
		}
	    }
	    return MSG_HANDLED;
	}
	break;

    default:
	return default_dlg_callback (h, msg, parm);
    }
}
Exemplo n.º 18
0
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;
}
Exemplo n.º 19
0
static cb_ret_t
edit_dialog_command_execute (Dlg_head * h, unsigned long command)
{
    gboolean ret = MSG_HANDLED;

    switch (command)
    {
    case CK_EditNew:
        edit_add_window (h, h->y + 1, h->x, h->lines - 2, h->cols, NULL, 0);
        break;
    case CK_EditFile:
        edit_load_cmd (h);
        break;
    case CK_EditSyntaxFile:
        edit_load_syntax_file (h);
        break;
    case CK_EditUserMenu:
        edit_load_menu_file (h);
        break;
    case CK_Close:
        /* if there are no opened files anymore, close MC editor */
        if (edit_widget_is_editor ((Widget *) h->current->data) &&
            edit_close_cmd ((WEdit *) h->current->data) && find_editor (h) == NULL)
            dlg_stop (h);
        break;
    case CK_Help:
        edit_help ();
        /* edit->force |= REDRAW_COMPLETELY; */
        break;
    case CK_Menu:
        edit_menu_cmd (h);
        break;
    case CK_Quit:
    case CK_Cancel:
        {
            Widget *w = (Widget *) h->current->data;

            if (!edit_widget_is_editor (w) || ((WEdit *) w)->drag_state == MCEDIT_DRAG_NORMAL)
                dlg_stop (h);
            else
                edit_restore_size ((WEdit *) w);
        }
        break;
    case CK_About:
        edit_about ();
        break;
    case CK_SyntaxOnOff:
        edit_syntax_onoff_cmd (h);
        break;
    case CK_ShowTabTws:
        edit_show_tabs_tws_cmd (h);
        break;
    case CK_ShowMargin:
        edit_show_margin_cmd (h);
        break;
    case CK_ShowNumbers:
        edit_show_numbers_cmd (h);
        break;
    case CK_Refresh:
        edit_refresh_cmd ();
        break;
    case CK_Shell:
        view_other_cmd ();
        break;
    case CK_LearnKeys:
        learn_keys ();
        break;
    case CK_WindowMove:
    case CK_WindowResize:
        if (edit_widget_is_editor ((Widget *) h->current->data))
            edit_handle_move_resize ((WEdit *) h->current->data, command);
        break;
    case CK_WindowList:
        edit_window_list (h);
        break;
    case CK_WindowNext:
        dlg_one_down (h);
        dlg_set_top_widget (h->current->data);
        break;
    case CK_WindowPrev:
        dlg_one_up (h);
        dlg_set_top_widget (h->current->data);
        break;
    case CK_Options:
        edit_options_dialog (h);
        break;
    case CK_OptionsSaveMode:
        edit_save_mode_cmd ();
        break;
    case CK_SaveSetup:
        save_setup_cmd ();
        break;
    default:
        ret = MSG_NOT_HANDLED;
        break;
    }

    return ret;
}