示例#1
0
文件: editdraw.c 项目: TomyLobo/mc
static inline void
edit_draw_this_char (WEdit * edit, off_t curs, long row, long start_column, long end_column)
{
    off_t b = edit_bol (edit, curs);

    edit_draw_this_line (edit, b, row, start_column, end_column);
}
示例#2
0
    int get_bracket()
    {
    	int cpos = colorer_edit_get_cursor(edit);
    	cpos = cpos - edit_bol(edit, cpos);

        if (pairMatch != null) {
            baseEditor->releasePairMatch(pairMatch);
        }
        pairMatch = baseEditor->searchGlobalPair(colorer_edit_cursline(edit), cpos);
        if (pairMatch != null && pairMatch->eline != -1) {
            //CLR_TRACE("MC", "find bracket:%d", pairMatch->eline);
            return colorer_get_line_pos(edit, pairMatch->eline) +
                   (pairMatch->topPosition ? pairMatch->end->end : pairMatch->end->start);
        }
        return -1;
    }
示例#3
0
文件: wordproc.c 项目: sfionov/mc-dev
static long
line_start (WEdit *edit, long line)
{
    long p, l;

    l = edit->curs_line;
    p = edit->curs1;

    if (line < l)
	p = edit_move_backward (edit, p, l - line);
    else if (line > l)
	p = edit_move_forward (edit, p, line - l, 0);

    p = edit_bol (edit, p);
    while (strchr ("\t ", edit_get_byte (edit, p)))
	p++;
    return p;
}
示例#4
0
文件: wordproc.c 项目: sfionov/mc-dev
/*
 * Find the start of the current paragraph for the purpose of formatting.
 * Return position in the file.
 */
static long
begin_paragraph (WEdit *edit, int force)
{
    int i;
    for (i = edit->curs_line - 1; i >= 0; i--) {
	if (line_is_blank (edit, i)) {
	    i++;
	    break;
	}
	if (force) {
	    if (bad_line_start (edit, line_start (edit, i))) {
		i++;
		break;
	    }
	}
    }
    return edit_move_backward (edit, edit_bol (edit, edit->curs1),
			       edit->curs_line - i);
}
示例#5
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));
}
示例#6
0
    int get_color(int byte_index)
    {
        int cur_pos = colorer_edit_get_cursor(edit);
	
        if (byte_index == -1) {
            return def_mc;
        }

        baseEditor->lineCountEvent(colorer_total_lines(edit));
        baseEditor->visibleTextEvent(colorer_top_line(edit), colorer_height(edit));

	int line = colorer_get_line(edit, byte_index);

        LineRegion *lr = baseEditor->getLineRegions(line);

        int line_offset = byte_index - edit_bol(edit, byte_index);
        
        if (pairMatch != null) {
            if (line == pairMatch->sline &&
                line_offset >= pairMatch->start->start &&
                line_offset < pairMatch->start->end)
            {
                return colorer_convert_color(pairMatch->start->styled());
            }
            if (line == pairMatch->eline &&
                line_offset >= pairMatch->end->start &&
                line_offset < pairMatch->end->end)
            {
                return colorer_convert_color(pairMatch->end->styled());
            }
        }

        for (LineRegion *next = lr; next != null; next = next->next){
            //CLR_TRACE("MC", "next:%d-%d rd=%s", next->start, next->end, next->region->getName()->getChars());
            if (next->start <= line_offset && (next->end > line_offset || next->end == -1)
                && next->rdef != null && !next->special) {
		return colorer_convert_color(next->styled());
            }
        }
        return def_mc;
    }
示例#7
0
    int find_visible_bracket()
    {
    	bool pairDrop = false;
    	int cpos = colorer_edit_get_cursor(edit);
    	cpos = cpos - edit_bol(edit, cpos);
    	
        if (pairMatch != null) {
            baseEditor->releasePairMatch(pairMatch);
            pairDrop = true;
        }

        // update state
        baseEditor->lineCountEvent(colorer_total_lines(edit));
        baseEditor->visibleTextEvent(colorer_top_line(edit), colorer_height(edit));

        pairMatch = baseEditor->searchLocalPair(colorer_edit_cursline(edit), cpos);
        if (pairMatch != null || pairDrop) {
            //CLR_TRACE("MC", "find_visible_bracket");
            return 1;
        }
        return 0;
    }
示例#8
0
文件: editdraw.c 项目: ryanlee/mc
static inline void
render_edit_text (WEdit * edit, long start_row, long start_column, long end_row, long end_column)
{
    static long prev_curs_row = 0;
    static long prev_curs = 0;

    Widget *w = (Widget *) edit;
    Dlg_head *h = w->owner;

    long row = 0, curs_row;
    int force = edit->force;
    long b;
    int y1, x1, y2, x2;

    int last_line;
    int last_column;

    /* draw only visible region */

    last_line = h->y + h->lines - 1;

    y1 = w->y;
    if (y1 > last_line - 1 /* buttonbar */ )
        return;

    last_column = h->x + h->cols - 1;

    x1 = w->x;
    if (x1 > last_column)
        return;

    y2 = w->y + w->lines - 1;
    if (y2 < h->y + 1 /* menubar */ )
        return;

    x2 = w->x + w->cols - 1;
    if (x2 < h->x)
        return;

    if ((force & REDRAW_IN_BOUNDS) == 0)
    {
        /* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
        /* draw only visible region */

        if (y2 <= last_line - 1 /* buttonbar */ )
            end_row = w->lines - 1;
        else if (y1 >= h->y + 1 /* menubar */ )
            end_row = h->lines - 1 - y1 - 1;
        else
            end_row = start_row + h->lines - 1 - 1;

        if (x2 <= last_column)
            end_column = w->cols - 1;
        else if (x1 >= h->x)
            end_column = h->cols - 1 - x1;
        else
            end_column = start_column + h->cols - 1;
    }

    /*
     * If the position of the page has not moved then we can draw the cursor
     * character only.  This will prevent line flicker when using arrow keys.
     */
    if ((force & REDRAW_CHAR_ONLY) == 0 || (force & REDRAW_PAGE) != 0)
    {
        if ((force & REDRAW_PAGE) != 0)
        {
            row = start_row;
            b = edit_move_forward (edit, edit->start_display, start_row, 0);
            while (row <= end_row)
            {
                if (key_pending (edit))
                    return;
                edit_draw_this_line (edit, b, row, start_column, end_column);
                b = edit_move_forward (edit, b, 1, 0);
                row++;
            }
        }
        else
        {
            curs_row = edit->curs_row;

            if ((force & REDRAW_BEFORE_CURSOR) != 0 && start_row < curs_row)
            {
                long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;

                row = start_row;
                b = edit->start_display;
                while (row <= upto)
                {
                    if (key_pending (edit))
                        return;
                    edit_draw_this_line (edit, b, row, start_column, end_column);
                    b = edit_move_forward (edit, b, 1, 0);
                }
            }

            /*          if (force & REDRAW_LINE)          ---> default */
            b = edit_bol (edit, edit->curs1);
            if (curs_row >= start_row && curs_row <= end_row)
            {
                if (key_pending (edit))
                    return;
                edit_draw_this_line (edit, b, curs_row, start_column, end_column);
            }

            if ((force & REDRAW_AFTER_CURSOR) != 0 && end_row > curs_row)
            {
                row = curs_row + 1 < start_row ? start_row : curs_row + 1;
                b = edit_move_forward (edit, b, 1, 0);
                while (row <= end_row)
                {
                    if (key_pending (edit))
                        return;
                    edit_draw_this_line (edit, b, row, start_column, end_column);
                    b = edit_move_forward (edit, b, 1, 0);
                    row++;
                }
            }

            if ((force & REDRAW_LINE_ABOVE) != 0 && curs_row >= 1)
            {
                row = curs_row - 1;
                b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
                if (row >= start_row && row <= end_row)
                {
                    if (key_pending (edit))
                        return;
                    edit_draw_this_line (edit, b, row, start_column, end_column);
                }
            }

            if ((force & REDRAW_LINE_BELOW) != 0 && row < edit->widget.lines - 1)
            {
                row = curs_row + 1;
                b = edit_bol (edit, edit->curs1);
                b = edit_move_forward (edit, b, 1, 0);
                if (row >= start_row && row <= end_row)
                {
                    if (key_pending (edit))
                        return;
                    edit_draw_this_line (edit, b, row, start_column, end_column);
                }
            }
        }
    }
    else if (prev_curs_row < edit->curs_row)
    {
        /* with the new text highlighting, we must draw from the top down */
        edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
        edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
    }
    else
    {
        edit_draw_this_char (edit, edit->curs1, edit->curs_row, start_column, end_column);
        edit_draw_this_char (edit, prev_curs, prev_curs_row, start_column, end_column);
    }

    edit->force = 0;

    prev_curs_row = edit->curs_row;
    prev_curs = edit->curs1;
}
示例#9
0
文件: editdraw.c 项目: ebichu/dd-wrt
/* cursor must be in screen for other than REDRAW_PAGE passed in force */
static void
render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
		  long end_column)
{
    long row = 0, curs_row;
    static int prev_curs_row = 0;
    static long prev_curs = 0;

    int force = edit->force;
    long b;

/*
 * If the position of the page has not moved then we can draw the cursor
 * character only.  This will prevent line flicker when using arrow keys.
 */
    if ((!(force & REDRAW_CHAR_ONLY)) || (force & REDRAW_PAGE)) {
	if (!(force & REDRAW_IN_BOUNDS)) {	/* !REDRAW_IN_BOUNDS means to ignore bounds and redraw whole rows */
	    start_row = 0;
	    end_row = edit->num_widget_lines - 1;
	    start_column = 0;
	    end_column = edit->num_widget_columns - 1;
	}
	if (force & REDRAW_PAGE) {
	    row = start_row;
	    b = edit_move_forward (edit, edit->start_display, start_row, 0);
	    while (row <= end_row) {
		if (key_pending (edit))
		    goto exit_render;
		edit_draw_this_line (edit, b, row, start_column, end_column);
		b = edit_move_forward (edit, b, 1, 0);
		row++;
	    }
	} else {
	    curs_row = edit->curs_row;

	    if (force & REDRAW_BEFORE_CURSOR) {
		if (start_row < curs_row) {
		    long upto = curs_row - 1 <= end_row ? curs_row - 1 : end_row;
		    row = start_row;
		    b = edit->start_display;
		    while (row <= upto) {
			if (key_pending (edit))
			    goto exit_render;
			edit_draw_this_line (edit, b, row, start_column, end_column);
			b = edit_move_forward (edit, b, 1, 0);
		    }
		}
	    }
/*          if (force & REDRAW_LINE)          ---> default */
	    b = edit_bol (edit, edit->curs1);
	    if (curs_row >= start_row && curs_row <= end_row) {
		if (key_pending (edit))
		    goto exit_render;
		edit_draw_this_line (edit, b, curs_row, start_column, end_column);
	    }
	    if (force & REDRAW_AFTER_CURSOR) {
		if (end_row > curs_row) {
		    row = curs_row + 1 < start_row ? start_row : curs_row + 1;
		    b = edit_move_forward (edit, b, 1, 0);
		    while (row <= end_row) {
			if (key_pending (edit))
			    goto exit_render;
			edit_draw_this_line (edit, b, row, start_column, end_column);
			b = edit_move_forward (edit, b, 1, 0);
			row++;
		    }
		}
	    }
	    if (force & REDRAW_LINE_ABOVE && curs_row >= 1) {
		row = curs_row - 1;
		b = edit_move_backward (edit, edit_bol (edit, edit->curs1), 1);
		if (row >= start_row && row <= end_row) {
		    if (key_pending (edit))
			goto exit_render;
		    edit_draw_this_line (edit, b, row, start_column, end_column);
		}
	    }
	    if (force & REDRAW_LINE_BELOW && row < edit->num_widget_lines - 1) {
		row = curs_row + 1;
		b = edit_bol (edit, edit->curs1);
		b = edit_move_forward (edit, b, 1, 0);
		if (row >= start_row && row <= end_row) {
		    if (key_pending (edit))
			goto exit_render;
		    edit_draw_this_line (edit, b, row, start_column, end_column);
		}
	    }
	}
    } else {
	if (prev_curs_row < edit->curs_row) {	/* with the new text highlighting, we must draw from the top down */
	    edit_draw_this_char (edit, prev_curs, prev_curs_row);
	    edit_draw_this_char (edit, edit->curs1, edit->curs_row);
	} else {
	    edit_draw_this_char (edit, edit->curs1, edit->curs_row);
	    edit_draw_this_char (edit, prev_curs, prev_curs_row);
	}
    }

    edit->force = 0;

    prev_curs_row = edit->curs_row;
    prev_curs = edit->curs1;

  exit_render:
    edit->screen_modified = 0;
    return;
}
示例#10
0
文件: editdraw.c 项目: ebichu/dd-wrt
static void edit_draw_this_char (WEdit * edit, long curs, long row)
{
    int b = edit_bol (edit, curs);
    edit_draw_this_line (edit, b, row, 0, edit->num_widget_columns - 1);
}
示例#11
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;
}
示例#12
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;
}