home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
TEDCOPY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-10-28
|
6KB
|
252 lines
/*
tedcopy.c
% ted block functions
C-scape 3.2
Copyright (c) 1988 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
6/01/88 jdc create
10/21/88 jmd Removed memory.h
12/22/88 jmd Added NULL test in ted_copy
3/24/89 jmd added sed_ macros
4/06/89 jmd made this match teddecl (int to boolean)
5/23/89 jdc made tb_setcursor menu_setcursor
5/24/89 jdc replaced sed_Repaint's with sed_Update's
8/04/89 jdc played with tb->set_cursor
11/04/89 jdc added paint optimization
11/10/89 jdc preened
12/15/89 jdc fixed cursor positioning
3/28/90 jmd ansi-fied
5/07/90 jmd changed '?' operation to if/else in ted_copy
10/28/90 jdc fixed boolean/int ret conflict
*/
#include "ted.h"
int ted_GetMark(sed_type sed)
{
tb_type tb;
tb = sed_GetTextbuf(sed);
return((tb->m_stop) ? TED_FIXMARK : tb->mark);
}
void ted_SetMark(sed_type sed, int mode)
/*
*/
{
tb_type tb;
int lmark;
tb = sed_GetTextbuf(sed);
if (mode == TED_FIXMARK) {
if (tb->mark == TED_NOMARK) {
tb->m_stop = FALSE;
}
else {
tb->m_stop = TRUE;
ted_GetPosition(sed, &(tb->markbox.cleat_row), &(tb->markbox.cleat_col));
tb->cleat = tb->cursor;
}
}
else {
lmark = tb->mark;
tb->mark = mode;
if (mode == TED_NOMARK) {
tb->m_stop = FALSE;
}
else {
ted_GetPosition(sed, &(tb->markbox.anchor_row), &(tb->markbox.anchor_col));
tb->anchor = tb->cursor;
ted_GetPosition(sed, &(tb->markbox.cleat_row), &(tb->markbox.cleat_col));
tb->cleat = tb->cursor;
}
if (!ted_GetRefresh(sed))
;
else if (lmark == TED_NOMARK && mode != TED_NOMARK) {
sed_RepaintRow(sed, tb->markbox.anchor_row,
tb->markbox.anchor_col, 1);
}
else {
win_Paint(sed);
}
}
}
boolean ted_copy(sed_type sed, menu_type cmenu, byte attr, int mode)
/*
*/
{
tb_type tb, copytb;
int row, col, srow, drow, width, newline, ins;
long cursor, len;
ocbox markbox;
boolean ret = TRUE;
tb = sed_GetTextbuf(sed);
if (tb->mark == TED_NOMARK) {
return(FALSE);
}
ted_GetPosition(sed, &row, &col);
cursor = tb->cursor;
if (cmenu == NULL) {
copytb = NULL;
}
else {
copytb = menu_GetTextbuf(cmenu);
}
if (mode & B_COPY) { /* clear copy buffer */
if (cmenu == NULL) {
mode &= ~B_COPY;
ret = FALSE;
}
else {
menu_ClearTB(cmenu);
}
}
box_sort(&markbox, &(tb->markbox), (tb->mark == TED_MARK) ? BOXSORT_ROW:BOXSORT_COL);
if (tb->mark == TED_MARK) { /* rowwise */
len = ((len = tb->anchor - tb->cleat) < 0) ? -len + 1 : len + 1;
if (mode & B_ATTR) {
tb_strattr(tb, markbox.toprow, markbox.leftcol, len, attr);
}
if (mode & B_COPY) {
copytb->buf_type = TED_MARK;
menu_strcpy(cmenu, 0, 0, tb, markbox.toprow, markbox.leftcol, len, TB_LEN);
}
if (mode & B_CUT) {
menu_strdel(sed_GetMenu(sed), markbox.toprow, markbox.leftcol, len);
tb->mark = TED_NOMARK; /* turn off marking if text is gone */
tb->m_stop = FALSE;
/* cursor placement. cases: before, in, & after marked block */
if (cursor > tb->cursor) {
if (cursor >= tb->cursor + len) { /* after */
tb->cursor = cursor - len;
}
else { /* in */
tb->cursor = cursor - (len - 1);
}
}
else { /* before */
tb->cursor = cursor;
}
menu_setcursor(sed_GetMenu(sed));
row = tb_GetRow(tb);
col = tb_GetCol(tb);
}
}
else { /* colunmwise */
width = markbox.rightcol - markbox.leftcol + 1;
/* work from the bottom up! */
for (srow = markbox.botrow, drow = markbox.botrow - markbox.toprow;
srow >= markbox.toprow; srow--, drow--) {
len = (long)tb_strlen(tb, srow, markbox.leftcol, width, &newline); /* calls tb_FindPosition */
if (mode & B_ATTR) {
tb_strattr(tb, srow, markbox.leftcol, len + (long)newline, attr);
}
if (mode & B_COPY) {
copytb->buf_type = TED_COLMARK;
menu_strcpy(cmenu, drow, 0, tb, srow, markbox.leftcol, len, TB_LEN);
}
if (mode & B_CUT) {
menu_strdel(sed_GetMenu(sed), srow, markbox.leftcol, len);
}
if (mode & B_PAD) {
if (tb->exp_len > markbox.rightcol + 1 + tb->nend) {
ins = tb->insert;
tb->insert = FALSE;
menu_Addc(sed_GetMenu(sed), srow, markbox.leftcol, ' ', markbox.rightcol - markbox.leftcol + 1);
tb->insert = ins;
}
else if (tb->exp_len > markbox.leftcol + tb->nend) {
menu_strdel(sed_GetMenu(sed), srow, markbox.leftcol, len);
}
}
}
if (mode & B_CUT) { /* turn off marking if text is gone */
tb->mark = TED_NOMARK;
tb->m_stop = FALSE;
/* cursor placement. cases: in or out of marked block */
if (row >= markbox.toprow && row <= markbox.botrow
&& col >= markbox.leftcol && col < markbox.leftcol + width) {
col = markbox.leftcol; /* in */
}
}
}
if (mode & B_COPY) {
tb_FindPosition(copytb, 0, 0);
}
ted_GotoPosition(sed, row, col);
if (ted_GetRefresh(sed) && mode & B_CUT) {
win_Paint(sed);
sed_SendBorderMsg(sed, BDM_SCROLL, NULL, NULL);
}
return(ret);
}
boolean ted_insert(sed_type sed, menu_type cmenu)
{
tb_type tb, copytb;
int row, col, srow, r;
int crow, ccol;
boolean ret = TRUE;
tb = sed_GetTextbuf(sed);
if (cmenu == NULL || (copytb = cmenu->textbuf)->buf_type == TED_NOMARK) {
return(FALSE);
}
crow = tb_GetRow(copytb); /* save cut buf pos */
ccol = tb_GetCol(copytb);
ted_GetPosition(sed, &row, &col);
if (copytb->buf_type == TED_COLMARK) { /* colwise insert */
for (srow = 0, r = row; tb_FindLine(copytb, srow) == TRUE; r++, srow++) {
if (!menu_strcpy(sed_GetMenu(sed), r, col, copytb, srow, 0,
(long)(copytb->len - copytb->nend), TB_LEN)) {
ret = FALSE;
}
}
}
else { /* rowwise insert */
if (!menu_strcpy(sed_GetMenu(sed), row, col, copytb, 0, 0, 0L, TB_ALL)) {
ret = FALSE;
}
}
tb_FindPosition(copytb, crow, ccol); /* restore cut buf pos */
if (tb_GetRow(tb) >= row) {
row = tb_GetRow(tb);
col = (tb_GetCol(tb) > col) ? tb_GetCol(tb) : col;
}
ted_GotoPosition(sed, row, col);
if (ted_GetRefresh(sed)) {
win_Paint(sed);
sed_SendBorderMsg(sed, BDM_SCROLL, NULL, NULL);
}
return(ret);
}