home *** CD-ROM | disk | FTP | other *** search
- /*
- menuputb.c
-
- % menu_putTB, menu_ClearTB, menu_setcursor
-
- C-scape 3.2
- Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- ---------------------
- 04/22/89 jdc fixed attr problem found by (NAME)?
- 05/23/89 jdc made tb_setcursor menu_setcursor
- speed up for no wrapping case
- 06/05/89 jdc added if (text != NULL) text += len, in overwrite
- 07/27/89 jdc put menu_SetDirty in menu_ClearTB
- 08/04/89 jdc played with tb->set_cursor
- 08/09/89 jdc made len and count longs
-
- 11/10/89 jdc added color optimization
- 12/12/89 jmd made colors bytes
- 3/28/90 jmd ansi-fied
- 10/28/90 jdc fixed boolean/int ret conflict
- 12/15/90 jdc fixed color problem
- */
-
- #include "menu.h"
-
- OSTATIC bblock_type bblock_end(bblock_type b);
-
- static bblock_type bblock_end(bblock_type b)
- {
- while (b->next != NULL) {
- b = b->next;
- }
- return(b);
- }
-
- boolean menu_putTB(menu_type menu, int row, int col, char *text, char chr, unsigned slen, byte color, byte old_color, int mode)
- /*
- takes DISPLAYED (expanded) position.
- mode == TB_COLOR, TB_SAMECOLOR
- */
- {
- tb_type tb;
- int ins, oldrow, spaces, color_newline = 0;
- long count, len;
- int asize;
- bblock_type b = NULL, ib;
- boolean ret = TRUE;
-
- cs_Assert(menu_Ok(menu), CS_TB_P_TB, 0);
- cs_Assert(row >= 0 && col >= 0, CS_TB_P_OOR, 0);
- tb = menu_GetTextbuf(menu);
- asize = tb->bbc->asize;
-
- if ((oldrow = tb_FindLine(tb, row)) <= 0) { /* row past the end */
-
- count = (long)(row + oldrow - 1); /* count number of new rows */
-
- if (!tb->limit || tb->size + count + 1L <= tb->max_size) {
-
- bbc_Set(tb->bbc, (long)tb->len, '\n', count, FALSE);
- if ((mode == TB_COLOR || mode == 3)
- && !bbc_Attr(tb->bbc, (long)tb->len, old_color, count)) {
- return(FALSE);
- }
-
- if (mode == TB_COLOR && color != old_color) {
- tb->bbc->asize = 1;
- b = bblock_open(tb->bbc, 1L, bblock_end(tb->bbc->b), color);
- }
- if (bbc_Set(tb->bbc, (long)tb->len+count, '\n', 1L, FALSE) == 0L) {
- return(FALSE);
- }
- tb->size += count + 1L;
- }
- oldrow = -oldrow;
- }
- else {
- oldrow = tb_GetRow(tb);
- }
- count = 0L;
- tb_FindPosition(tb, row, col); /* set cursor */
- spaces = col - (tb->exp_len - tb->nend); /* tb->exp_len includes '\n' */
- len = (long)(tb->len - tb->nend); /* tb->len includes '\n' */
- col = (int)(tb->cursor - tb->offset); /* unexpand col */
-
- if (spaces > 0) { /* past end of line */
-
- if (tb->limit && tb->size + spaces > tb->max_size) {
- return(FALSE);
- }
- if (bbc_work(tb->bbc, (long)len, NULL, ' ', (long)spaces, BBC_INSERT) == 0L) {
- return(FALSE);
- }
- if ((mode == TB_COLOR || mode == 3)
- && !bbc_Attr(tb->bbc, len, old_color, (long)spaces)) {
- ret = FALSE;
- }
- tb->size += spaces;
- len += (long)spaces;
- col += spaces;
- }
- if (tb->insert == TED_INSERT || spaces >= 0) {
- ins = TRUE;
- if ((long)col >= len && tb->nend && TB_COLOR) {
- color_newline = 1;
- }
- }
- else if ((len = len - (long)col) <= (long)slen) { /* overwrite till line end */
- if (tb->nend && TB_COLOR) {
- color_newline = 1;
- }
- if (len > 0L) {
- if ((len = bbc_work(tb->bbc, (long)col, text, chr, len, FALSE)) == 0) {
- ret = FALSE;
- }
- if ((mode == TB_COLOR || mode == 3)
- && !bbc_Attr(tb->bbc, (long)col, color, len + (long)color_newline)) {
- ret = FALSE;
- }
- col += (int)len;
- if (text != NULL) {
- text += (int)len;
- }
- slen -= (unsigned int)len;
- }
- ins = TRUE;
- }
- else {
- ins = FALSE;
- }
-
- if (slen > 0) {
- if (ins && tb->limit && tb->size + slen > tb->max_size) {
- ret = FALSE;
- }
- else {
- if (bbc_work(tb->bbc, (long)col, text, chr, (long)slen,
- (b != NULL && ins) ? BBC_ENDINS:ins) == 0L) {
- ret = FALSE;
- }
- else {
- if (ins) {
- tb->size += slen;
- }
- count += slen;
- }
- slen += color_newline;
- if (mode == TB_COLOR || mode == 3) {
- if (b != NULL) {
- for (ib = b; ib != NULL; ib = ib->next) {
- ib->attr = color;
- }
- }
- else if (!bbc_Attr(tb->bbc, (long)col, color, (long)slen)) {
- ret = FALSE;
- }
- }
- }
- }
- /* find the cursor position */
- tb->cursor = tb->offset + (long)col + count;
-
- if (tb->width < 32000) {
- /* move back in case of funny wrapping */
- tb_FindLine(tb, (oldrow <= 1) ? 0 : oldrow - 1);
- }
- menu_setcursor(menu);
-
- /* menu_SetDirty(menu, TRUE); keep track of menu size manually */
- if ((row = tb_GetRow(tb)) > oldrow) {
- if (tb->insert) {
- menu->rowcount += row - oldrow;
- }
- else if (row >= menu->rowcount) {
- menu->rowcount = row + 1;
- }
- }
- tb->bbc->asize = asize;
-
- return(ret);
- }
-
- menu_type menu_ClearTB(menu_type menu)
- {
- bbc_Close((menu_GetTextbuf(menu))->bbc);
-
- tb_setup(menu_GetTextbuf(menu));
-
- menu_SetDirty(menu, TRUE);
-
- return(menu);
- }
-
- int menu_setcursor(menu_type menu)
- /*
- sets hints after adding to textbuffer
- */
- {
- tb_type tb;
- unsigned int expan, i, count;
- bbpeek_struct bp;
- int dlen, row;
-
- tb = menu->textbuf;
- row = tb_GetRow(tb);
-
- /* move back */
- while ( tb->offset > tb->cursor ) {
- if ( --row < 0 ) {
- tb->cursor = 0;
- }
- tb_FindLine(tb, row);
- }
-
- /* move forward */
- for ( ; tb_FindLine(tb, row) == TRUE; row++ ) {
-
- if ( tb->exp_len > menu->colcount ) { /* check size */
- menu->colcount = tb->exp_len;
- }
- if ( tb->offset + (long)tb->len > tb->cursor ) { /* position cursor */
- bp.b = tb->bbc->b;
- bp.off = bp.b->off;
- bp.len = (long)tb->len;
- count = (unsigned int)(tb->cursor - tb->offset);
- expan = 0;
- do {
- for ( dlen = bbpeek(&bp), i = 0; i < dlen; i++, count-- ) {
-
- if ( count <= 0 ) {
- tb->col = expan;
- return(tb->cursor_set = TRUE);
- }
- expan += tb_translate(tb, expan, bp.p + i);
- }
- bp.off += dlen;
- bp.len -= (long)dlen;
-
- } while( dlen > 0 );
- }
- }
- tb->cursor = tb->offset + (long)tb->len - 1L; /* cursor on last char */
- tb->col = tb->exp_len - 1;
-
- return(tb->cursor_set = FALSE);
- }
-
-
-
-