示例#1
0
 void setPosition(int pos)
 {
     start = pos;
     //CLR_TRACE("MC", "setPosition start=%d", pos);
     len = edit_eol(edit, pos) - start;
     if (colorer_edit_get_byte(edit, start+len-1) ==  '\r') {
         len--;
     }
     //CLR_TRACE("MC", "setPosition len=%d", len);
     assert(len >= 0);
 }
示例#2
0
文件: wordproc.c 项目: sfionov/mc-dev
/*
 * Find the end of the current paragraph for the purpose of formatting.
 * Return position in the file.
 */
static long
end_paragraph (WEdit *edit, int force)
{
    int i;
    for (i = edit->curs_line + 1; i <= edit->total_lines; i++) {
	if (line_is_blank (edit, i)) {
	    i--;
	    break;
	}
	if (force)
	    if (bad_line_start (edit, line_start (edit, i))) {
		i--;
		break;
	    }
    }
    return edit_eol (edit,
		     edit_move_forward (edit, edit_bol (edit, edit->curs1),
					i - edit->curs_line, 0));
}
示例#3
0
文件: editdraw.c 项目: ryanlee/mc
static void
edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_col)
{
    struct line_s line[MAX_LINE_LEN];
    struct line_s *p = line;

    long m1 = 0, m2 = 0, q, c1, c2;
    int col, start_col_real;
    unsigned int c;
    int color;
    int abn_style;
    int i;
    int utf8lag = 0;
    unsigned int cur_line = 0;
    int book_mark = 0;
    char line_stat[LINE_STATE_WIDTH + 1] = "\0";

    if (row > edit->widget.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET)
        return;

    if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
        book_mark = BOOK_MARK_COLOR;
    else if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_FOUND_COLOR))
        book_mark = BOOK_MARK_FOUND_COLOR;

    if (book_mark)
        abn_style = book_mark << 16;
    else
        abn_style = MOD_ABNORMAL;

    end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;

    edit_get_syntax_color (edit, b - 1, &color);
    q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
    start_col_real = (col = (int) edit_move_forward3 (edit, b, 0, q)) + edit->start_col;
    if (option_line_state)
    {
        cur_line = edit->start_line + row;
        if (cur_line <= (unsigned int) edit->total_lines)
        {
            g_snprintf (line_stat, LINE_STATE_WIDTH + 1, "%7i ", cur_line + 1);
        }
        else
        {
            memset (line_stat, ' ', LINE_STATE_WIDTH);
            line_stat[LINE_STATE_WIDTH] = '\0';
        }
        if (book_mark_query_color (edit, cur_line, BOOK_MARK_COLOR))
        {
            g_snprintf (line_stat, 2, "*");
        }
    }

    if (col + 16 > -edit->start_col)
    {
        eval_marks (edit, &m1, &m2);

        if (row <= edit->total_lines - edit->start_line)
        {
            long tws = 0;
            if (tty_use_colors () && visible_tws)
            {
                tws = edit_eol (edit, b);
                while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' ' || c == '\t'))
                    tws--;
            }

            while (col <= end_col - edit->start_col)
            {
                int cw = 1;

                p->ch = 0;
                p->style = 0;
                if (q == edit->curs1)
                    p->style |= MOD_CURSOR;
                if (q >= m1 && q < m2)
                {
                    if (edit->column_highlight)
                    {
                        int x;
                        x = edit_move_forward3 (edit, b, 0, q);
                        c1 = min (edit->column1, edit->column2);
                        c2 = max (edit->column1, edit->column2);
                        if (x >= c1 && x < c2)
                            p->style |= MOD_MARKED;
                    }
                    else
                        p->style |= MOD_MARKED;
                }
                if (q == edit->bracket)
                    p->style |= MOD_BOLD;
                if (q >= edit->found_start && q < edit->found_start + edit->found_len)
                    p->style |= MOD_BOLD;

                if (!edit->utf8)
                {
                    c = edit_get_byte (edit, q);
                }
                else
                {
                    c = edit_get_utf (edit, q, &cw);
                }
                /* we don't use bg for mc - fg contains both */
                if (book_mark)
                {
                    p->style |= book_mark << 16;
                }
                else
                {
                    edit_get_syntax_color (edit, q, &color);
                    p->style |= color << 16;
                }
                switch (c)
                {
                case '\n':
                    col = (end_col + utf8lag) - edit->start_col + 1;    /* quit */
                    break;
                case '\t':
                    i = TAB_SIZE - ((int) col % TAB_SIZE);
                    col += i;
                    if (tty_use_colors () &&
                        ((visible_tabs || (visible_tws && q >= tws)) && enable_show_tabs_tws))
                    {
                        if (p->style & MOD_MARKED)
                            c = p->style;
                        else if (book_mark)
                            c |= book_mark << 16;
                        else
                            c = p->style | MOD_WHITESPACE;
                        if (i > 2)
                        {
                            p->ch = '<';
                            p->style = c;
                            p++;
                            while (--i > 1)
                            {
                                p->ch = '-';
                                p->style = c;
                                p++;
                            }
                            p->ch = '>';
                            p->style = c;
                            p++;
                        }
                        else if (i > 1)
                        {
                            p->ch = '<';
                            p->style = c;
                            p++;
                            p->ch = '>';
                            p->style = c;
                            p++;
                        }
                        else
                        {
                            p->ch = '>';
                            p->style = c;
                            p++;
                        }
                    }
                    else if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
                    {
                        p->ch = '.';
                        p->style |= MOD_WHITESPACE;
                        c = p->style & ~MOD_CURSOR;
                        p++;
                        while (--i)
                        {
                            p->ch = ' ';
                            p->style = c;
                            p++;
                        }
                    }
                    else
                    {
                        p->ch |= ' ';
                        c = p->style & ~MOD_CURSOR;
                        p++;
                        while (--i)
                        {
                            p->ch = ' ';
                            p->style = c;
                            p++;
                        }
                    }
                    break;
                case ' ':
                    if (tty_use_colors () && visible_tws && q >= tws && enable_show_tabs_tws)
                    {
                        p->ch = '.';
                        p->style |= MOD_WHITESPACE;
                        p++;
                        col++;
                        break;
                    }
                    /* fallthrough */
                default:
#ifdef HAVE_CHARSET
                    if (mc_global.utf8_display)
                    {
                        if (!edit->utf8)
                        {
                            c = convert_from_8bit_to_utf_c ((unsigned char) c, edit->converter);
                        }
                    }
                    else if (edit->utf8)
                        c = convert_from_utf_to_current_c (c, edit->converter);
                    else
#endif
                        c = convert_to_display_c (c);

                    /* Caret notation for control characters */
                    if (c < 32)
                    {
                        p->ch = '^';
                        p->style = abn_style;
                        p++;
                        p->ch = c + 0x40;
                        p->style = abn_style;
                        p++;
                        col += 2;
                        break;
                    }
                    if (c == 127)
                    {
                        p->ch = '^';
                        p->style = abn_style;
                        p++;
                        p->ch = '?';
                        p->style = abn_style;
                        p++;
                        col += 2;
                        break;
                    }
                    if (!edit->utf8)
                    {
                        if ((mc_global.utf8_display && g_unichar_isprint (c)) ||
                            (!mc_global.utf8_display && is_printable (c)))
                        {
                            p->ch = c;
                            p++;
                        }
                        else
                        {
                            p->ch = '.';
                            p->style = abn_style;
                            p++;
                        }
                    }
                    else
                    {
                        if (g_unichar_isprint (c))
                        {
                            p->ch = c;
                            p++;
                        }
                        else
                        {
                            p->ch = '.';
                            p->style = abn_style;
                            p++;
                        }
                    }
                    col++;
                    break;
                }               /* case */

                q++;
                if (cw > 1)
                {
                    q += cw - 1;
                }
            }
        }
    }
    else
    {
        start_col_real = start_col = 0;
    }

    p->ch = '\0';

    print_to_widget (edit, row, start_col, start_col_real, end_col, line, line_stat, book_mark);
}
示例#4
0
文件: editdraw.c 项目: ebichu/dd-wrt
/* b is a pointer to the beginning of the line */
static void
edit_draw_this_line (WEdit *edit, long b, long row, long start_col,
		     long end_col)
{
    static unsigned int line[MAX_LINE_LEN];
    unsigned int *p = line;
    long m1 = 0, m2 = 0, q, c1, c2;
    int col, start_col_real;
    unsigned int c;
    int color;
    int i;

    edit_get_syntax_color (edit, b - 1, &color);
    q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
    start_col_real = (col =
		      (int) edit_move_forward3 (edit, b, 0,
						q)) + edit->start_col;
    c1 = min (edit->column1, edit->column2);
    c2 = max (edit->column1, edit->column2);

    if (col + 16 > -edit->start_col) {
	eval_marks (edit, &m1, &m2);

	if (row <= edit->total_lines - edit->start_line) {
		long tws;
	    if (use_colors && visible_tws) {
		tws = edit_eol (edit, b);
		while (tws > b && ((c = edit_get_byte (edit, tws - 1)) == ' '
				   || c == '\t'))
		    tws--;
	    }

	    while (col <= end_col - edit->start_col) {
		*p = 0;
		if (q == edit->curs1)
		    *p |= MOD_CURSOR;
		if (q >= m1 && q < m2) {
		    if (column_highlighting) {
			int x;
			x = edit_move_forward3 (edit, b, 0, q);
			if (x >= c1 && x < c2)
			    *p |= MOD_MARKED;
		    } else
			*p |= MOD_MARKED;
		}
		if (q == edit->bracket)
		    *p |= MOD_BOLD;
		if (q >= edit->found_start
		    && q < edit->found_start + edit->found_len)
		    *p |= MOD_BOLD;
		c = edit_get_byte (edit, q);
/* we don't use bg for mc - fg contains both */
		edit_get_syntax_color (edit, q, &color);
		*p |= color << 16;
		switch (c) {
		case '\n':
		    col = end_col - edit->start_col + 1;	/* quit */
		    *(p++) |= ' ';
		    break;
		case '\t':
		    i = TAB_SIZE - ((int) col % TAB_SIZE);
		    col += i;
		    if (use_colors && visible_tabs) {
			c = (*p & ~MOD_CURSOR) | MOD_WHITESPACE;
			if (i > 2) {
			    *(p++) |= '<' | MOD_WHITESPACE;
			    while (--i > 1)
				*(p++) = c | '-';
			    *(p++) = c | '>';
			} else if (i > 1) {
			    *(p++) |= '<' | MOD_WHITESPACE;
			    *(p++) = c | '>';
			} else
			    *(p++) |= '>' | MOD_WHITESPACE;
		    } else if (use_colors && visible_tws && q >= tws) {
			*p |= '.' | MOD_WHITESPACE;
			c = *(p++) & ~MOD_CURSOR;
			while (--i)
			    *(p++) = c;
		    } else {
			*p |= ' ';
			c = *(p++) & ~MOD_CURSOR;
			while (--i)
			    *(p++) = c;
		    }
		    break;
		case ' ':
		    if (use_colors && visible_tws && q >= tws) {
			*(p++) |= '.' | MOD_WHITESPACE;
			col++;
			break;
		    }
		    /* fallthrough */
		default:
		    c = convert_to_display_c (c);

		    /* Caret notation for control characters */
		    if (c < 32) {
			*(p++) = '^' | MOD_ABNORMAL;
			*(p++) = (c + 0x40) | MOD_ABNORMAL;
			col += 2;
			break;
		    }
		    if (c == 127) {
			*(p++) = '^' | MOD_ABNORMAL;
			*(p++) = '?' | MOD_ABNORMAL;
			col += 2;
			break;
		    }

		    if (is_printable (c)) {
			*(p++) |= c;
		    } else {
			*(p++) = '.' | MOD_ABNORMAL;
		    }
		    col++;
		    break;
		}
		q++;
	    }
	}
    } else {
	start_col_real = start_col = 0;
    }
    *p = 0;

    print_to_widget (edit, row, start_col, start_col_real, end_col, line);
}
示例#5
0
文件: editwidget.c 项目: artzub/mc
static int
edit_event (Gpm_Event * event, void *data)
{
    WEdit *edit = (WEdit *) data;

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

    edit_update_curs_row (edit);
    edit_update_curs_col (edit);

    /* Outside editor window */
    if (event->y < 1 || event->x < 1
        || event->x > edit->widget.cols || event->y > edit->widget.lines)
        return MOU_NORMAL;

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

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

    if (event->type & (GPM_DOWN | GPM_UP))
        edit_push_key_press (edit);

    if (!option_cursor_beyond_eol)
        edit->prev_col = event->x - edit->start_col - option_line_state_width - 1;
    else
    {
        long line_len = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
                                            edit_eol (edit, edit->curs1));

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

    --event->y;
    if (event->y > edit->curs_row)
        edit_move_down (edit, event->y - edit->curs_row, 0);
    else if (event->y < edit->curs_row)
        edit_move_up (edit, edit->curs_row - event->y, 0);
    else
        edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1));

    if (event->type & GPM_DOWN)
    {
        edit_mark_cmd (edit, 1);        /* reset */
        edit->highlight = 0;
    }

    if (!(event->type & GPM_DRAG))
        edit_mark_cmd (edit, 0);

  update:
    edit_find_bracket (edit);
    edit->force |= REDRAW_COMPLETELY;
    edit_update_curs_row (edit);
    edit_update_curs_col (edit);
    edit_update_screen (edit);

    return MOU_NORMAL;
}
示例#6
0
文件: editwidget.c 项目: TomyLobo/mc
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 == edit->widget.cols - dx - 1)
        {
            edit_dialog_callback (w->owner, NULL, DLG_ACTION, CK_Close, NULL);
            return MOU_NORMAL;
        }

        if (local.x == edit->widget.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 = edit_move_forward3 (edit, edit_bol (edit, edit->curs1), 0,
                                                    edit_eol (edit, edit->curs1));

                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_bol (edit, edit->curs1));

            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)
            {
                Dlg_head *h = 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 (h);
            }
        }

    return MOU_NORMAL;
}