home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
TBSTR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-15
|
5KB
|
207 lines
/*
tbstr.c
% textbuffer string manipulation functions, keep track of menu->vheight
C-scape 3.2
Copyright (c) 1988 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
6/08/88 jdc created
8/21/88 jmd preened and poked
removed ret from deleterow
10/10/88 jdc cleaned up tb_strcpy
12/02/88 jdc preened and poked
5/23/89 jdc made tb_setcursor menu_setcursor
5/24/89 jdc fixed multiple line menu_strdel bug
7/15/89 ted changed 'bbc_Attr == NULL' to '!bbc_Attr()'. (It's boolean).
8/04/89 jdc played with tb->set_cursor
3/28/90 jmd ansi-fied
12/15/90 jdc added TB_COLORNNL support
*/
#include "menu.h"
int menu_strcpy(menu_type dmenu, int drow, int dcol, tb_type stb, int srow, int scol, long len, int mode)
/*
takes DISPLAYED (expanded) position.
if mode == TB_ALL then copy all of source (stb) to destination (dtb)
*/
{
tb_type dtb;
bbpeek_struct bp;
int dlen;
dtb = menu_GetTextbuf(dmenu);
if (!tb_FindPosition(stb, srow, scol)) {
return(FALSE);
}
if (mode == TB_ALL) {
/* don't include last '\n' */
len = stb->size - stb->cursor - 1;
}
bp.b = stb->bbc->b;
bp.off = bp.b->off + tb_GetCursor(stb);
bp.len = len;
while ((dlen = bbpeek(&bp)) > 0) {
if (!menu_putTB(dmenu, drow, dcol, bp.p, 0x00, dlen, bp.b->attr, 0, TB_COLORNNL)) {
return(FALSE);
}
drow = tb_GetRow(dtb);
dcol = tb_GetCol(dtb);
bp.off += dlen;
bp.len -= (long)dlen;
}
return(TRUE);
}
long menu_strdel(menu_type menu, unsigned int row, unsigned int col, long len)
/*
takes DISPLAYED (expanded) position.
*/
{
tb_type tb;
long count, cursor;
int dlen, llen, nline, oldrow;
tb = menu_GetTextbuf(menu);
if (row <= 0) {
nline = FALSE;
row = 0;
}
else {
tb_FindLine(tb, row - 1);
nline = tb->nend;
}
tb_FindPosition(tb, row, col);
if ((oldrow = tb_GetRow(tb)) < row) {
return(0L);
}
cursor = tb->cursor;
for (col = tb_GetCursor(tb), count = 0L; len > 0L && tb_FindLine(tb, row) == TRUE;) {
if (col > tb->len) {
row++;
if (!tb_FindLine(tb, row)) {
break;
}
col = tb_GetCursor(tb);
}
llen = tb->len - col;
dlen = (len < (long)llen) ? (int)len : llen;
/* can't delete last '\n' */
if (tb->size - tb->offset <= (long)(col + dlen)) {
if (col != 0 || !nline) {
dlen = tb->len - col - 1;
}
}
if (dlen == 0) {
break;
}
tb->size -= bbc_Del(tb->bbc, (long)col, (long)dlen);
count += dlen;
len -= dlen;
if (!tb->nend) {
/* word wrapping */
if (tb->size < 200) {
/* small enough to recount */
menu_SetDirty(menu, TRUE);
}
else {
/* guess ! */
menu->rowcount = (int)(tb->size / (long)tb->width);
}
}
else if (dlen == llen) {
/* adjust menu->rowcount directly */
menu->rowcount--;
}
if (tb->offset >= tb->size) {
if (tb_GetRow(tb) == -1L) {
tb->offset = tb->size;
}
else {
tb->offset = tb->size - (tb->bbc->b->len - tb->bbc->b->off);
}
}
}
tb_FindLine(menu_GetTextbuf(menu), (oldrow <= 1) ? 0 : oldrow - 1);
tb->cursor = cursor;
menu_setcursor(menu);
return(count);
}
int tb_strlen(tb_type tb, unsigned int row, unsigned int col, unsigned int width, int *newline)
/*
returns char width for displayed width, doesn't include '\n'.
*newline == 1 if it hits a '\n', else *newline == 0
*/
{
bbpeek_struct bp;
int len, i, dlen, done;
if (!tb_FindPosition(tb, row, col)) {
return(0);
}
bp.b = tb->bbc->b;
bp.off = bp.b->off + tb_GetCursor(tb);
bp.len = tb->len;
for (width += col, len = 0, *newline = 0, done = FALSE; !done;) {
for (dlen = bbpeek(&bp), i = 0; i < dlen; i++, len++) {
if (col >= width) {
done = TRUE;
break;
}
if (bp.p[i] == '\n') {
*newline = 1;
done = TRUE;
break;
}
col += tb_translate(tb, col, bp.p + i);
}
bp.off += i;
}
return(len);
}
int tb_strattr(tb_type tb, unsigned int row, unsigned int col, long len, byte attr)
/*
takes DISPLAYED (expanded) position.
*/
{
if (!tb_FindPosition(tb, row, col) ||
!bbc_Attr(tb->bbc, tb->cursor - tb->offset, attr, len)) {
return(FALSE);
}
return(TRUE);
}
int menu_DelRowTB(menu_type menu, int row, int col)
/*
takes DISPLAYED (expanded) position.
*/
{
tb_type tb;
tb = menu_GetTextbuf(menu);
if (!tb_FindPosition(tb, row, col)
|| menu_strdel(menu, row, col, (long)(tb->len - tb_GetCursor(tb))) == 0L) {
return(FALSE);
}
return(TRUE);
}