/* * _AddLine - add a line to the lines data structures */ void _AddLine( LPWDATA w, const void *in_data, unsigned len ) { int i; BOOL hadbreak; HWND hwnd; int tabcnt = 0; int nlcnt = 0; int curbufoff = 0; const char *data; #ifdef _MBCS static char leadByte; static int leadByteWaiting; unsigned char ch[MB_CUR_MAX+1]; LPBYTE p; #else char ch; #endif data = (const char *)in_data; hwnd = w->hwnd; _AccessWinLines(); if( w->LineTail != NULL && !w->LineTail->has_cr ) { FARstrcpy( w->tmpbuff->data, w->LineTail->data ); #ifdef _MBCS curbufoff = FAR_mbslen( (LPBYTE)w->tmpbuff->data ); #else curbufoff = FARstrlen( w->tmpbuff->data ); #endif if( curbufoff > w->buffoff ) { w->buffoff = curbufoff; } } if( w->no_advance ) { curbufoff = 0; } for( i = 0; i < len; i ++ ) { w->no_advance = FALSE; do { hadbreak = FALSE; #ifdef _MBCS /* MBCS */ if( tabcnt ) { _mbccpy( ch, (unsigned char *)" " ); /* copy the character */ ch[_mbclen( ch )] = '\0'; /* terminate char with NULL */ tabcnt--; } else if( nlcnt ) { _mbccpy( ch, (unsigned char *)"\n" ); /* copy the character */ ch[_mbclen( ch )] = '\0'; /* terminate char with NULL */ nlcnt--; } else { if( !leadByteWaiting ) { if( _ismbblead( *data ) ) { leadByteWaiting = 1; leadByte = *data; ch[0] = '\0'; } else { ch[0] = *data; ch[1] = '\0'; } } else { leadByteWaiting = 0; ch[0] = leadByte; ch[1] = *data; ch[2] = '\0'; } data++; } if( !_mbccmp( ch, (unsigned char *)"\t" ) ) { tabcnt = TAB( curbufoff + 1 ); continue; } else if( !_mbccmp( ch, (unsigned char *)"\f" ) ) { nlcnt = w->height; continue; } else if( !_mbccmp( ch, (unsigned char *)"\r" ) ) { curbufoff = 0; w->no_advance = TRUE; w->tmpbuff->has_cr = TRUE; continue; } else if( !_mbccmp( ch, (unsigned char *)"\n" ) ) { hadbreak = TRUE; newLine( w ); curbufoff = w->buffoff; } else if( !_mbccmp( ch, (unsigned char *)"\b" ) ) { if( curbufoff > 0 ) { p = FAR_mbsninc( (LPBYTE)w->tmpbuff->data, curbufoff - 1 ); if( _ismbblead( *p ) ) { *p = ' '; /* stomp lead byte */ /* char split into 2; don't change curbufoff */ } else { curbufoff--; /* back up one character */ } } } else if( ch[0] != '\0' ) { FAR_mbccpy( FAR_mbsninc( (LPBYTE)w->tmpbuff->data, curbufoff ), ch ); curbufoff++; if( curbufoff > w->buffoff ) { w->buffoff = curbufoff; } if( TOOWIDE( w->buffoff, w ) ) { hadbreak = TRUE; newLine( w ); curbufoff = w->buffoff; } } #else /* SBCS */ if( tabcnt ) { ch = ' '; tabcnt--; } else if( nlcnt ) { ch = '\n'; nlcnt--; } else { ch = data[i]; } if( ch == '\t' ) { tabcnt = TAB( curbufoff + 1 ); continue; } else if( ch == '\f' ) { nlcnt = w->height; continue; } else if( ch == '\r' ) { curbufoff = 0; w->no_advance = TRUE; w->tmpbuff->has_cr = TRUE; continue; } else if( ch == '\n' ) { hadbreak = TRUE; newLine( w ); curbufoff = w->buffoff; } else if( ch == '\b' ) { if( curbufoff > 0 ) { curbufoff--; } } else { w->tmpbuff->data[curbufoff++] = ch; if( curbufoff > w->buffoff ) { w->buffoff = curbufoff; } if( TOOWIDE( w->buffoff, w ) ) { hadbreak = TRUE; newLine( w ); curbufoff = w->buffoff; } } #endif } while( tabcnt || nlcnt ); } if( !hadbreak ) { updateBuff( w ); } _ReleaseWinLines(); } /* _AddLine */
/* * _DisplayLineInWindowWithColor - as it sounds! */ void _DisplayLineInWindowWithColor( LPWDATA w, int line, LPSTR text, int c1, int c2, int extra, int startcol ) { #ifdef _MBCS LPBYTE tmp; #else LPSTR tmp; #endif char buff[256]; int start,end,a,spend,cnt1,cnt2; WORD i; HWND hwnd; hwnd = w->hwnd; /*** Find dimensions of line ***/ #ifdef _MBCS tmp = FAR_mbsninc( (LPBYTE)text, startcol ); a = FAR_mbslen( tmp ); if( line < 1 || line >= w->height ) return; start = 0; spend = end = w->width - extra; if( end > a ) end = a; cnt1 = FAR_mbsnbcnt( tmp, end - start ); cnt2 = spend - end; FAR_mbsnbcpy( (LPBYTE)buff, tmp, cnt1 - start ); FARmemset( buff + cnt1, ' ', cnt2 ); tmp = FAR_mbsninc( (LPBYTE)buff, cnt1 + cnt2 ); *tmp = '\0'; #else tmp = text; tmp += startcol; a = FARstrlen( tmp ); if( line < 1 || line >= w->height ) return; start = 0; spend = end = w->width - extra; if( end > a ) end = a; cnt1 = end - start; cnt2 = spend - end; FARmemcpy( buff, tmp, cnt1 ); FARmemset( buff + cnt1, ' ', cnt2 ); buff[cnt1 + cnt2] = 0; #endif line--; #if defined( __OS2__ ) { RECTL rcl; HPS ps; POINTL ptl; POINTL points[TXTBOX_COUNT]; ptl.x = 0; ptl.y = (w->y2 - w->y1) - (line+1)*w->ychar + w->base_offset; ps = WinGetPS( hwnd ); _SelectFont( ps ); GpiQueryTextBox( ps, startcol, w->tmpbuff->data, TXTBOX_COUNT, points ); rcl.xLeft = points[TXTBOX_BOTTOMRIGHT].x; #ifdef _MBCS GpiQueryTextBox( ps, __mbslen( (unsigned char *)buff ), buff, TXTBOX_COUNT, points ); #else GpiQueryTextBox( ps, strlen( buff ), buff, TXTBOX_COUNT, points ); #endif rcl.xRight = points[TXTBOX_BOTTOMRIGHT].x; rcl.yTop = (w->y2 - w->y1) - line*w->ychar; rcl.yBottom = rcl.yTop - w->ychar; WinFillRect( ps, &rcl, c1 ); GpiSetColor( ps, c2 ); #ifdef _MBCS GpiCharStringAt( ps, &ptl, _mbsnbcnt(buff,w->width), buff ); #else GpiCharStringAt( ps, &ptl, w->width, buff ); #endif WinReleasePS( ps ); } #else { HDC dc; // SIZE size; // RECT rect; dc = GetDC( hwnd ); _SetMyDC( dc, _ColorMap[c2], _ColorMap[c1] ); // #ifdef __NT__ // GetTextExtentPoint32( dc, buff, strlen(buff), &size ); // #else // GetTextExtentPoint( dc, buff, strlen(buff), &size ); // #endif // #ifdef _MBCS TextOut( dc, 0, line * w->ychar, (LPSTR)buff, FAR_mbsnbcnt( (LPBYTE)buff, w->width ) ); #else TextOut( dc, 0, line * w->ychar, buff, w->width ); #endif /*** Clear to end of line to remove any residue ***/ // GetClientRect( w->hwnd, &rect ); // rect.top = line * w->ychar; // rect.bottom = (line+1) * w->ychar ; // rect.left = size.cx; // FillRect( dc, &rect, w->brush ); ReleaseDC( hwnd, dc ); } #endif /*** Update the w->image array ***/ #ifdef _MBCS { mb_char mbc; unsigned char *curMbc; int count; i = line * w->width + startcol; for( count = 0, curMbc = (unsigned char *)buff; count < w->width - startcol; count++ ) { mbc = _mbsnextc( curMbc ); /* get the character */ curMbc = _mbsinc( curMbc ); /* point to next char */ w->image[i + count] = mbc; /* store it in w->image */ } } #else i = line * w->width + startcol; FARmemcpy( &w->image[i], buff, w->width - startcol ); #endif } /* _DisplayLineInWindowWithColor */
void _RepaintWindow( LPWDATA w, PRECT rcPaint, HDC ph ) #endif { WORD i; WORD ptop, pbot, pleft, pright, poff, pdown; WORD width; #ifdef _MBCS mb_char _WCI86FAR *image; unsigned char mbc[MB_CUR_MAX + 1]; #else LPSTR image; #endif #if !defined( __OS2__ ) HFONT oldfont; #endif /* * get area to redraw */ ptop = rcPaint->top / w->ychar; if( ptop > 0 && ( rcPaint->top % w->ychar ) != 0 ) ptop--; pbot = rcPaint->bottom / w->ychar ; if( pbot == 0 ) return; if( pbot >= w->height ) pbot = w->height - 1; if( ( rcPaint->bottom % w->ychar ) == 0 ) pbot--; pleft = 0; pright = w->width - 1; width = w->width; poff = pleft * w->xchar; pdown = ptop * w->ychar; /* * draw all lines */ #if defined( __OS2__ ) #else oldfont = SelectObject( (HDC)ph, _FixedFont ); #endif for( i = ptop; i <= pbot; i++ ) { image = &w->image[i * w->width]; #if defined( __OS2__ ) { POINTL ptl; ptl.x = poff; ptl.y = ( w->y2 - w->y1 ) - ( pdown + w->ychar ) + w->base_offset; #ifdef _MBCS { WORD count; LPSTR buff; buff = FARmalloc( sizeof( mb_char ) * ( width + 1 ) ); if( buff == NULL ) _OutOfMemoryExit(); *buff = '\0'; for( count = 0; count < width; count++ ) { _mbvtop( image[pleft + count], mbc ); mbc[_mbclen( mbc )] = '\0'; FARstrcat( buff, (char *)mbc ); } GpiCharStringAt( (HPS)ph, &ptl, FAR_mbsnbcnt( (PBYTE)buff, width ), buff ); FARfree( buff ); } #else GpiCharStringAt( (HPS)ph, &ptl, width, &image[pleft] ); #endif } #else SetBkColor( (HDC)ph, _ColorMap[w->background_color] ); SetTextColor( (HDC)ph, _ColorMap[w->text_color] ); #ifdef _MBCS { WORD count; size_t bytes; LPSTR buff; buff = FARmalloc( sizeof( mb_char ) * ( width + 1 ) ); if( buff == NULL ) _OutOfMemoryExit(); *buff = '\0'; for( count = 0; count < width; count++ ) { _mbvtop( image[pleft + count], mbc ); mbc[_mbclen( mbc )] = '\0'; FARstrcat( buff, (LPSTR)mbc ); } bytes = FARstrlen( buff ); TextOut( (HDC)ph, poff, pdown, buff, bytes ); FARfree( buff ); } #else TextOut( (HDC)ph, poff, pdown, &image[pleft], width ); #endif #endif pdown += w->ychar; } #if !defined( __OS2__ ) SelectObject( (HDC)ph, oldfont ); #endif } /* _RepaintWindow */