Example #1
0
/**
 * Handle move/resize mouse events.
 */
static void
edit_mouse_handle_move_resize (Widget * w, mouse_msg_t msg, mouse_event_t * event)
{
    WEdit *edit = (WEdit *) (w);
    Widget *h = WIDGET (w->owner);
    int global_x, global_y;

    if (msg == MSG_MOUSE_UP)
    {
        /* Exit move/resize mode. */
        edit_execute_cmd (edit, CK_Enter, -1);
        edit_update_screen (edit);      /* Paint the buttonbar over our possibly overlapping frame. */
        return;
    }

    if (msg != MSG_MOUSE_DRAG)
        /**
         * We ignore any other events. Specifically, MSG_MOUSE_DOWN.
         *
         * When the move/resize is initiated by the menu, we let the user
         * stop it by clicking with the mouse. Which is why we don't want
         * a mouse down to affect the window.
         */
        return;

    /* Convert point to global coordinates for easier calculations. */
    global_x = event->x + w->x;
    global_y = event->y + w->y;

    /* Clamp the point to the dialog's client area. */
    global_y = CLAMP (global_y, h->y + 1, h->y + h->lines - 2); /* Status line, buttonbar */
    global_x = CLAMP (global_x, h->x, h->x + h->cols - 1);      /* Currently a no-op, as the dialog has no left/right margins. */

    if (edit->drag_state == MCEDIT_DRAG_MOVE)
    {
        w->y = global_y;
        w->x = global_x - edit->drag_state_start;
    }
    else if (edit->drag_state == MCEDIT_DRAG_RESIZE)
    {
        w->lines = MAX (WINDOW_MIN_LINES, global_y - w->y + 1);
        w->cols = MAX (WINDOW_MIN_COLS, global_x - w->x + 1);
    }

    edit->force |= REDRAW_COMPLETELY;   /* Not really needed as WEdit's MSG_DRAW already does this. */

    /* We draw the whole dialog because dragging/resizing exposes area beneath. */
    dlg_redraw (w->owner);
}
Example #2
0
/**
 * Handle mouse events of editor window
 *
 * @param w Widget object (the editor window)
 * @param msg mouse event message
 * @param event mouse event data
 */
static void
edit_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event)
{
    WEdit *edit = (WEdit *) w;
    /* buttons' distance from right edge */
    int dx = edit->fullscreen ? 0 : 2;
    /* location of 'Close' and 'Toggle fullscreen' pictograms */
    int close_x, toggle_fullscreen_x;

    close_x = (w->cols - 1) - dx - 1;
    toggle_fullscreen_x = close_x - 3;

    if (edit->drag_state != MCEDIT_DRAG_NONE)
    {
        /* window is being resized/moved */
        edit_mouse_handle_move_resize (w, msg, event);
        return;
    }

    /* If it's the last line on the screen, we abort the event to make the
     * system channel it to the overlapping buttonbar instead. We have to do
     * this because a WEdit has the WOP_TOP_SELECT flag, which makes it above
     * the buttonbar in Z-order. */
    if (msg == MSG_MOUSE_DOWN && (event->y + w->y == LINES - 1))
    {
        event->result.abort = TRUE;
        return;
    }

    switch (msg)
    {
    case MSG_MOUSE_DOWN:
        widget_select (w);
        edit_update_curs_row (edit);
        edit_update_curs_col (edit);

        if (!edit->fullscreen)
        {
            if (event->y == 0)
            {
                if (event->x >= close_x - 1 && event->x <= close_x + 1)
                    ;           /* do nothing (see MSG_MOUSE_CLICK) */
                else if (event->x >= toggle_fullscreen_x - 1 && event->x <= toggle_fullscreen_x + 1)
                    ;           /* do nothing (see MSG_MOUSE_CLICK) */
                else
                {
                    /* start window move */
                    edit_execute_cmd (edit, CK_WindowMove, -1);
                    edit_update_screen (edit);  /* Paint the buttonbar over our possibly overlapping frame. */
                    edit->drag_state_start = event->x;
                }
                break;
            }

            if (event->y == w->lines - 1 && event->x == w->cols - 1)
            {
                /* bottom-right corner -- start window resize */
                edit_execute_cmd (edit, CK_WindowResize, -1);
                break;
            }
        }

        MC_FALLTHROUGH;         /* to start/stop text selection */

    case MSG_MOUSE_UP:
        edit_update_cursor (edit, event);
        edit_total_update (edit);
        break;

    case MSG_MOUSE_CLICK:
        if (event->y == 0)
        {
            if (event->x >= close_x - 1 && event->x <= close_x + 1)
                send_message (w->owner, NULL, MSG_ACTION, CK_Close, NULL);
            else if (event->x >= toggle_fullscreen_x - 1 && event->x <= toggle_fullscreen_x + 1)
                edit_toggle_fullscreen (edit);
            else if (!edit->fullscreen && event->count == GPM_DOUBLE)
                /* double click on top line (toggle fullscreen) */
                edit_toggle_fullscreen (edit);
        }
        else if (event->count == GPM_DOUBLE)
        {
            /* double click */
            edit_mark_current_word_cmd (edit);
            edit_total_update (edit);
        }
        else if (event->count == GPM_TRIPLE)
        {
            /* triple click: works in GPM only, not in xterm */
            edit_mark_current_line_cmd (edit);
            edit_total_update (edit);
        }
        break;

    case MSG_MOUSE_DRAG:
        edit_update_cursor (edit, event);
        edit_total_update (edit);
        break;

    case MSG_MOUSE_SCROLL_UP:
        edit_move_up (edit, 2, TRUE);
        edit_total_update (edit);
        break;

    case MSG_MOUSE_SCROLL_DOWN:
        edit_move_down (edit, 2, TRUE);
        edit_total_update (edit);
        break;

    default:
        break;
    }
}
Example #3
0
void
format_paragraph (WEdit * edit, gboolean force)
{
    off_t p, q;
    long lines;
    off_t size;
    GString *t;
    long indent;
    unsigned char *t2;
    gboolean utf8 = FALSE;

    if (option_word_wrap_line_length < 2)
        return;
    if (edit_line_is_blank (edit, edit->buffer.curs_line))
        return;

    p = begin_paragraph (edit, force, &lines);
    q = end_paragraph (edit, force);
    indent = test_indent (edit, p, q);

    t = get_paragraph (&edit->buffer, p, q, indent != 0);
    size = t->len - 1;

    if (!force)
    {
        off_t i;
        char *stop_format_chars;

        if (option_stop_format_chars != NULL
            && strchr (option_stop_format_chars, t->str[0]) != NULL)
        {
            g_string_free (t, TRUE);
            return;
        }

        if (option_stop_format_chars == NULL || *option_stop_format_chars == '\0')
            stop_format_chars = g_strdup ("\t");
        else
            stop_format_chars = g_strconcat (option_stop_format_chars, "\t", (char *) NULL);

        for (i = 0; i < size - 1; i++)
            if (t->str[i] == '\n' && strchr (stop_format_chars, t->str[i + 1]) != NULL)
            {
                g_free (stop_format_chars);
                g_string_free (t, TRUE);
                return;
            }

        g_free (stop_format_chars);
    }

    t2 = (unsigned char *) g_string_free (t, FALSE);
#ifdef HAVE_CHARSET
    utf8 = edit->utf8;
#endif
    /* scroll up to show 1st line of paragraph */
    edit_move_up (edit, lines, TRUE);
    /* scroll left as much as possible to show the formatted paragraph */
    edit_scroll_left (edit, -edit->start_col);

    format_this (t2, q - p, indent, utf8);
    put_paragraph (edit, t2, p, indent, size);
    g_free ((char *) t2);

    /* move to the end of paragraph */
    q = end_paragraph (edit, force);
    edit_cursor_move (edit, q - edit->buffer.curs1);

    /* try move to the start of next paragraph */
    if (edit->buffer.curs_line < edit->buffer.lines)
    {
        edit_execute_cmd (edit, CK_Home, -1);

        do
        {
            edit_execute_cmd (edit, CK_Down, -1);
        }
        while (edit->buffer.curs_line < edit->buffer.lines
               && edit_line_is_blank (edit, edit->buffer.curs_line));
    }
}