diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 60b549f45d..6f2c8d36c1 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,43 @@ +20000418-13:30 GMT+1 Ryszard Glab + + *include/hbapigt.h + *source/rtl/gtapi.c + *source/rtl/gtdos/gtdos.c + *source/rtl/gtcrs/gtcrs.c + *source/rtl/gtos2/gtos2.c + *source/rtl/gtpca/gtpca.c + *source/rtl/gtsln/gtsln.c + *source/rtl/gtstd/gtstd.c + *source/rtl/gtwin/gtwin.c + *source/rtl/gt_tpl/gt_tpl.c + *box drawing procedures moved from gtapi.c to low level + modules - this will allow to use native (optimized) method + of box drawing (xterm!) + *full implementation of low level hb_gt_Replicate() + *added hb_gt_HorizLine() and hb_gt_VertLine() - this can be + extended by definition of HB_LINE() or + @ row,left,right LINE command (this will get line drawing + support on platforms where @ ... BOX command is not suitable) + + *source/common/hbver.c + *fixed REGS union access + + *source/rtl/gtcrs/gtcrs.c + *support for box drawing added for xterm + NOTE: Only + @ y1,x1 TO y2,x2 + and + @ y1,x1 TO y2,x2 DOUBLE + are reliable although both are drawing a single-line box + The usual @ y1,x1,y2,x2 BOX ... depends on character mapping + used in current font + (Well I am not so familiar with it then this needs some + more work - I can be wrong here :) + + If you want a single method of box drawing for all platforms use + @ y1,x1 TO y2,x2 + + 20000418-00:42 DST Paul Tucker * makefile.vc + source/lang/msghe862.c diff --git a/harbour/include/hbapigt.h b/harbour/include/hbapigt.h index f7a9c28d9c..6dcc32052e 100644 --- a/harbour/include/hbapigt.h +++ b/harbour/include/hbapigt.h @@ -74,11 +74,15 @@ extern "C" { #define HB_CLR_MAX_ HB_CLR_UNSELECTED /* strings for borders (same as box.ch, but defined for use by C) */ - /*01234567*/ + /*01234567*/ #define _B_SINGLE "ÚÄ¿³ÙÄÀ³" #define _B_DOUBLE "ÉÍ»º¼ÍȺ" #define _B_SINGLE_DOUBLE "ÖÄ·º½ÄÓº" #define _B_DOUBLE_SINGLE "Õ͸³¾ÍÔ³" +#define _B_SINGLE_V '³' +#define _B_SINGLE_H 'Ä' +#define _B_DOUBLE_V 'º' +#define _B_DOUBLE_H 'Í' /* Keyboard filters */ @@ -151,6 +155,9 @@ extern char * hb_gtVersion( void ); extern void hb_gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr ); extern void hb_gt_Exit( void ); extern BOOL hb_gt_AdjustPos( BYTE * pStr, ULONG ulLen ); +extern USHORT hb_gt_Box( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyBox, BYTE attrib ); +extern USHORT hb_gt_BoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyBox, BYTE attrib ); +extern USHORT hb_gt_BoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyBox, BYTE attrib ); extern SHORT hb_gt_Col( void ); extern void hb_gt_DispBegin( void ); extern USHORT hb_gt_DispCount( void ); @@ -160,12 +167,13 @@ extern USHORT hb_gt_GetCursorStyle( void ); extern USHORT hb_gt_GetScreenHeight( void ); extern USHORT hb_gt_GetScreenWidth( void ); extern void hb_gt_GetText( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyDst ); +extern USHORT hb_gt_HorizLine( USHORT uiRow, USHORT uiLeft, USHORT uiRight, BYTE byChar, BYTE byAttr ); extern BOOL hb_gt_IsColor( void ); extern void hb_gt_Puts( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE * pbyStr, ULONG ulLen ); extern void hb_gt_PutText( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbySrc ); extern int hb_gt_ReadKey( HB_inkey_enum eventmask ); extern int hb_gt_RectSize( USHORT rows, USHORT cols ); -extern void hb_gt_Replicate( BYTE byChar, ULONG ulLen ); +extern void hb_gt_Replicate( USHORT uiTop, USHORT uiLeft, BYTE byAttr, BYTE byChar, ULONG ulLen ); extern SHORT hb_gt_Row( void ); extern void hb_gt_Scroll( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE byAttr, SHORT iRows, SHORT iCols ); extern void hb_gt_SetAttribute( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE byAttr ); @@ -175,6 +183,7 @@ extern BOOL hb_gt_SetMode( USHORT uiRows, USHORT uiCols ); extern void hb_gt_SetPos( SHORT iRow, SHORT iCol ); extern void hb_gt_Tone( double dFrequency, double dDuration ); extern char * hb_gt_Version( void ); +extern USHORT hb_gt_VertLine( USHORT uiCol, USHORT uiTop, USHORT uiBottom, BYTE byChar, BYTE byAttr ); /* Keyboard related declarations */ diff --git a/harbour/source/common/hbver.c b/harbour/source/common/hbver.c index 2b68e7f138..f478866274 100644 --- a/harbour/source/common/hbver.c +++ b/harbour/source/common/hbver.c @@ -106,7 +106,7 @@ char * hb_verPlatform( void ) /* Host OS detection: Windows 2.x, 3.x, 95/98 */ { - regs.x.ax = 0x1600; + regs.HB_XREGS.ax = 0x1600; HB_DOS_INT86( 0x2F, ®s, ®s ); if( regs.h.al != 0x00 && regs.h.al != 0x80 ) @@ -125,10 +125,10 @@ char * hb_verPlatform( void ) /* Host OS detection: Windows NT/2000 */ { - regs.x.ax = 0x3306; + regs.HB_XREGS.ax = 0x3306; HB_DOS_INT86( 0x21, ®s, ®s ); - if( regs.x.bx == 0x3205 ) + if( regs.HB_XREGS.bx == 0x3205 ) strcat( pszPlatform, " (Windows NT/2000)" ); } diff --git a/harbour/source/rtl/gt_tpl/gt_tpl.c b/harbour/source/rtl/gt_tpl/gt_tpl.c index a18acba6b5..6c1584fadf 100644 --- a/harbour/source/rtl/gt_tpl/gt_tpl.c +++ b/harbour/source/rtl/gt_tpl/gt_tpl.c @@ -225,6 +225,17 @@ void hb_gt_SetCursorStyle( USHORT uiStyle ) } } +void hb_gt_xPutch( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_xPutch(%hu, %hu, %d, %i)", uiRow, uiCol, (int) byAttr, byChar)); + + HB_SYMBOL_UNUSED( uiRow ); + HB_SYMBOL_UNUSED( uiCol ); + HB_SYMBOL_UNUSED( byAttr ); + HB_SYMBOL_UNUSED( pbyStr ); + HB_SYMBOL_UNUSED( ulLen ); +} + void hb_gt_Puts( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE * pbyStr, ULONG ulLen ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_Puts(%hu, %hu, %d, %p, %lu)", uiRow, uiCol, (int) byAttr, pbyStr, ulLen)); @@ -323,20 +334,6 @@ BOOL hb_gt_SetMode( USHORT uiRows, USHORT uiCols ) HB_SYMBOL_UNUSED( uiCols ); } -void hb_gt_Replicate( BYTE byChar, ULONG ulLen ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%d, %lu)", (int) byChar, ulLen)); - - /* TODO: this will write character c nlength times to the screen. - Note that it is not used yet - If there is no native function that supports this, it is - already handled in a generic way by higher level functions. - */ - - HB_SYMBOL_UNUSED( byChar ); - HB_SYMBOL_UNUSED( ulLen ); -} - BOOL hb_gt_GetBlink() { HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetBlink()")); @@ -376,3 +373,62 @@ USHORT hb_gt_DispCount() { return s_uiDispCount; } + + +void hb_gt_Replicate( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar, ULONG nLength ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%hu, %hu, %i, %i, %lu)", uiRow, uiCol, byAttr, byChar, nLength)); + { + /* TODO: replace it with native (optimized) version */ + while( nLength-- ) + hb_gt_xPutch( uiRow, uiCol++, byAttr, byChar ); + } +} + +USHORT hb_gt_Box( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, + BYTE *szBox, BYTE byAttr ) +{ + + HB_SYMBOL_UNUSED( uiTop ); + HB_SYMBOL_UNUSED( uiLeft ); + HB_SYMBOL_UNUSED( uiBottom ); + HB_SYMBOL_UNUSED( uiRight ); + HB_SYMBOL_UNUSED( szBox ); + HB_SYMBOL_UNUSED( byAttr ); + return 0; +} + +USHORT hb_gt_BoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_BoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_HorizLine( USHORT uiRow, USHORT uiLeft, USHORT uiRight, BYTE byChar, BYTE byAttr ) +{ + if( uiLeft < uiRight ) + hb_gt_Replicate( uiRow, uiLeft, byAttr, byChar, uiRight - uiLeft + 1 ); + else + hb_gt_Replicate( uiRow, uiRight, byAttr, byChar, uiLeft - uiRight + 1 ); + return 0; +} + +USHORT hb_gt_VertLine( USHORT uiCol, USHORT uiTop, USHORT uiBottom, BYTE byChar, BYTE byAttr ) +{ + USHORT uRow; + + if( uiTop <= uiBottom ) + uRow = uiTop; + else + { + uRow = uiBottom; + uiBottom = uiTop; + } + while( uRow <= uiBottom ) + hb_gt_xPutch( uRow++, uiCol, byAttr, byChar ); + return 0; +} diff --git a/harbour/source/rtl/gtapi.c b/harbour/source/rtl/gtapi.c index 1c58830fd0..01c2beaa98 100644 --- a/harbour/source/rtl/gtapi.c +++ b/harbour/source/rtl/gtapi.c @@ -168,101 +168,29 @@ USHORT hb_gtBox( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, B if( uiTop < uiMaxRow && uiBottom < uiMaxRow && uiLeft < uiMaxCol && uiRight < uiMaxCol ) { - BYTE szBox[ 10 ]; + /* NOTE: For full compatibility, pad box string with last char if too + short [vszakats] */ + USHORT tmp; BYTE cPadChar; + BYTE szBox[ 10 ]; - USHORT uiRow; - USHORT uiCol; - USHORT uiHeight; - USHORT uiWidth; - - USHORT uiTopBak = uiTop; - USHORT uiLeftBak = uiLeft; - - /* NOTE: For full compatibility, pad box string with last char if too - short [vszakats] */ + cPadChar = ' '; + for( tmp = 0; *pbyFrame && tmp < 9; tmp++ ) + cPadChar = szBox[ tmp ] = *pbyFrame++; + while( tmp < 8 ) + szBox[ tmp++ ] = cPadChar; + szBox[ tmp ] = '\0'; + if( uiTop != uiBottom ) { - USHORT tmp; - - cPadChar = ' '; - for( tmp = 0; *pbyFrame && tmp < 9; tmp++ ) - cPadChar = szBox[ tmp ] = *pbyFrame++; - while( tmp < 8 ) - szBox[ tmp++ ] = cPadChar; - szBox[ tmp ] = '\0'; - } - - /* Ensure that box is drawn from top left to bottom right. */ - if( uiTop > uiBottom ) - { - USHORT tmp = uiTop; - uiTop = uiBottom; - uiBottom = tmp; - } - if( uiLeft > uiRight ) - { - USHORT tmp = uiLeft; - uiLeft = uiRight; - uiRight = tmp; - } - - uiRow = uiTop; - uiCol = uiLeft; - - /* Draw the box or line as specified */ - uiHeight = uiBottom - uiTop + 1; - uiWidth = uiRight - uiLeft + 1; - - hb_gtDispBegin(); - - if( uiHeight > 1 && uiWidth > 1 ) - hb_gtWriteAt( uiRow, uiCol, szBox + 0, sizeof( BYTE ) ); /* Upper left corner */ - - uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); - - if( uiCol <= uiRight ) - hb_gtRepChar( uiRow, uiCol, szBox[ 1 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Top line */ - - if( uiHeight > 1 && uiWidth > 1 ) - hb_gtWriteAt( uiRow, uiRight, szBox + 2, sizeof( BYTE ) ); /* Upper right corner */ - - if( szBox[ 8 ] && uiHeight > 2 && uiWidth > 2 ) - { - for( uiRow = uiTop + 1; uiRow < uiBottom; uiRow++ ) - { - uiCol = uiLeft; - hb_gtWriteAt( uiRow, uiCol++, szBox + 7, sizeof( BYTE ) ); /* Left side */ - hb_gtRepChar( uiRow, uiCol , szBox[ 8 ], uiRight - uiLeft - 1 ); /* Fill */ - hb_gtWriteAt( uiRow, uiRight, szBox + 3, sizeof( BYTE ) ); /* Right side */ - } + if( uiLeft != uiRight ) + hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, szBox, ( BYTE ) s_pColor[ s_uiColorIndex ] ); + else + hb_gt_VertLine( uiLeft, uiTop, uiBottom, szBox[ 3 ], ( BYTE ) s_pColor[ s_uiColorIndex ] ); } else - { - for( uiRow = ( uiWidth > 1 ? uiTop + 1 : uiTop ); uiRow < ( uiWidth > 1 ? uiBottom : uiBottom + 1 ); uiRow++ ) - { - hb_gtWriteAt( uiRow, uiLeft, szBox + 7, sizeof( BYTE ) ); /* Left side */ - if( uiWidth > 1 ) - hb_gtWriteAt( uiRow, uiRight, szBox + 3, sizeof( BYTE ) ); /* Right side */ - } - } - - if( uiHeight > 1 && uiWidth > 1 ) - { - hb_gtWriteAt( uiBottom, uiLeft, szBox + 6, sizeof( BYTE ) ); /* Bottom left corner */ - - uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); - - if( uiCol <= uiRight && uiHeight > 1 ) - hb_gtRepChar( uiBottom, uiCol, szBox[ 5 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Bottom line */ - - hb_gtWriteAt( uiBottom, uiRight, szBox + 4, sizeof( BYTE ) ); /* Bottom right corner */ - } - - hb_gtDispEnd(); - - hb_gtSetPos( uiTopBak + 1, uiLeftBak + 1 ); - + hb_gt_HorizLine( uiTop, uiLeft, uiRight, szBox[ 1 ], ( BYTE ) s_pColor[ s_uiColorIndex ] ); + hb_gtSetPos( uiTop + 1, uiLeft + 1 ); return 0; } else @@ -271,12 +199,58 @@ USHORT hb_gtBox( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, B USHORT hb_gtBoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight ) { - return hb_gtBox( uiTop, uiLeft, uiBottom, uiRight, ( BYTE * ) _B_DOUBLE ); + USHORT uiMaxRow; + USHORT uiMaxCol; + + uiMaxRow = hb_gt_GetScreenHeight(); + uiMaxCol = hb_gt_GetScreenWidth(); + + if( uiTop < uiMaxRow && uiBottom < uiMaxRow && + uiLeft < uiMaxCol && uiRight < uiMaxCol ) + { + if( uiTop != uiBottom ) + { + if( uiLeft != uiRight ) + hb_gt_BoxD( uiTop, uiLeft, uiBottom, uiRight, ( BYTE * ) _B_DOUBLE, ( BYTE ) s_pColor[ s_uiColorIndex ] ); + else + hb_gt_VertLine( uiLeft, uiTop, uiBottom, _B_DOUBLE_H, ( BYTE ) s_pColor[ s_uiColorIndex ] ); + } + else + hb_gt_HorizLine( uiTop, uiLeft, uiRight, _B_DOUBLE_V, ( BYTE ) s_pColor[ s_uiColorIndex ] ); + hb_gtSetPos( uiTop + 1, uiLeft + 1 ); + + return 0; + } + else + return 1; } USHORT hb_gtBoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight ) { - return hb_gtBox( uiTop, uiLeft, uiBottom, uiRight, ( BYTE * ) _B_SINGLE ); + USHORT uiMaxRow; + USHORT uiMaxCol; + + uiMaxRow = hb_gt_GetScreenHeight(); + uiMaxCol = hb_gt_GetScreenWidth(); + + if( uiTop < uiMaxRow && uiBottom < uiMaxRow && + uiLeft < uiMaxCol && uiRight < uiMaxCol ) + { + if( uiTop != uiBottom ) + { + if( uiLeft != uiRight ) + hb_gt_BoxS( uiTop, uiLeft, uiBottom, uiRight, ( BYTE * ) _B_SINGLE, ( BYTE ) s_pColor[ s_uiColorIndex ] ); + else + hb_gt_VertLine( uiLeft, uiTop, uiBottom, _B_SINGLE_V, ( BYTE ) s_pColor[ s_uiColorIndex ] ); + } + else + hb_gt_HorizLine( uiTop, uiLeft, uiRight, _B_SINGLE_H, ( BYTE ) s_pColor[ s_uiColorIndex ] ); + hb_gtSetPos( uiTop + 1, uiLeft + 1 ); + + return 0; + } + else + return 1; } USHORT hb_gtColorSelect( USHORT uiColorIndex ) @@ -730,22 +704,8 @@ USHORT hb_gtRepChar( USHORT uiRow, USHORT uiCol, BYTE byChar, USHORT uiCount ) { HB_TRACE(HB_TR_DEBUG, ("hb_gtRepChar(%hu, %hu, %d, %hu)", uiRow, uiCol, (int) byChar, uiCount)); - if( uiCount <= REPCHAR_BUFFER_SIZE ) - { - BYTE buffer[ REPCHAR_BUFFER_SIZE ]; - - memset( buffer, byChar, uiCount ); - hb_gtWriteAt( uiRow, uiCol, buffer, uiCount ); - } - else - { - BYTE * buffer = ( BYTE * ) hb_xgrab( uiCount ); - - memset( buffer, byChar, uiCount ); - hb_gtWriteAt( uiRow, uiCol, buffer, uiCount ); - - hb_xfree( buffer ); - } + hb_gt_Replicate( uiRow, uiCol, ( BYTE ) s_pColor[ s_uiColorIndex ], + byChar, uiCount ); return 0; } diff --git a/harbour/source/rtl/gtcrs/gtcrs.c b/harbour/source/rtl/gtcrs/gtcrs.c index 8b2a18823a..367dcc30ab 100644 --- a/harbour/source/rtl/gtcrs/gtcrs.c +++ b/harbour/source/rtl/gtcrs/gtcrs.c @@ -63,8 +63,9 @@ struct key_map_struc static struct key_map_struc *s_keymap_table = NULL; static unsigned s_attribmap_table[ 256 ]; /* mapping from DOS style attributes */ -static BOOL s_under_buggy_xterm; +static BOOL s_under_xterm; static int s_alternate_char_set; +static char s_xTermBox[ 10 ] = "lqkxjqmx "; static void hb_gt_Initialize_Terminal( void ) { @@ -93,21 +94,21 @@ static void hb_gt_Initialize_Terminal( void ) 15 white 7-> BOLD WHITE */ static char color_map[] = { 0, 4, 2, 6, 1, 5, 3, 7 }; - + start_color(); for( backg=0; backg> 4 ) & 0x07; /* bits 4-6, bit 7 is blinking attribute */ - foreg = ( i & 0x07 ); - s_attribmap_table[ i ] = COLOR_PAIR( backg*COLORS + foreg ); - if( i & 0x08 ) - s_attribmap_table[ i ] |= A_BOLD; /* 4-th bit is an intensity bit */ - if( i & 0x80 ) - s_attribmap_table[ i ] |= A_BLINK; /* 7-th bit is blinking bit */ + foreg = ( i & 0x07 ); + s_attribmap_table[ i ] = COLOR_PAIR( backg*COLORS + foreg ); + if( i & 0x08 ) + s_attribmap_table[ i ] |= A_BOLD; /* 4-th bit is an intensity bit */ + if( i & 0x80 ) + s_attribmap_table[ i ] |= A_BLINK; /* 7-th bit is blinking bit */ } } @@ -117,33 +118,23 @@ static void hb_gt_Initialize_Terminal( void ) scrollok( stdscr, TRUE ); raw(); keypad( stdscr, FALSE ); - - s_under_buggy_xterm = !strncmp( getenv("TERM"), "xterm", 5 ); + + s_under_xterm = !strncmp( getenv("TERM"), "xterm", 5 ); /* NOTE: using A_ALTCHARSET attribute is causing that small letters - a-z are not printed under xterm (at least xterm from Linux + a-z are not printed under xterm (at least xterm from Linux RedHat 6.1 distribution) */ - if( s_under_buggy_xterm ) + if( s_under_xterm ) { -/* - char * str; - - str = tigetstr( "enacs" ); / * enable alt character set * / - if( (str != NULL) && (str != (char *)-1) ) - write( fileno(stdout), str, strlen(str) ); - - str = tigetstr( "smacs" ); / * start alt characters set * / - if( (str != NULL) && (str != (char *)-1) ) - write( fileno(stdout), str, strlen(str) ); -*/ s_alternate_char_set = 0; } else + { s_alternate_char_set = A_ALTCHARSET; - + } bkgdset( ' ' ); ripoffline( 0, NULL ); - + } void hb_gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr ) @@ -208,43 +199,43 @@ void hb_gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr ) hb_gt_Add_keymap( K_ALT_C, "\033c" ); hb_gt_Add_keymap( K_ALT_C, "\033C" ); hb_gt_Add_keymap( K_ALT_D, "\033d" ); - hb_gt_Add_keymap( K_ALT_D, "\033D" ); + hb_gt_Add_keymap( K_ALT_D, "\033D" ); hb_gt_Add_keymap( K_ALT_E, "\033e" ); - hb_gt_Add_keymap( K_ALT_E, "\033E" ); + hb_gt_Add_keymap( K_ALT_E, "\033E" ); hb_gt_Add_keymap( K_ALT_F, "\033f" ); - hb_gt_Add_keymap( K_ALT_F, "\033F" ); + hb_gt_Add_keymap( K_ALT_F, "\033F" ); hb_gt_Add_keymap( K_ALT_G, "\033g" ); hb_gt_Add_keymap( K_ALT_G, "\033G" ); hb_gt_Add_keymap( K_ALT_H, "\033h" ); - hb_gt_Add_keymap( K_ALT_H, "\033H" ); + hb_gt_Add_keymap( K_ALT_H, "\033H" ); hb_gt_Add_keymap( K_ALT_I, "\033i" ); - hb_gt_Add_keymap( K_ALT_I, "\033I" ); + hb_gt_Add_keymap( K_ALT_I, "\033I" ); hb_gt_Add_keymap( K_ALT_J, "\033j" ); - hb_gt_Add_keymap( K_ALT_J, "\033J" ); + hb_gt_Add_keymap( K_ALT_J, "\033J" ); hb_gt_Add_keymap( K_ALT_K, "\033k" ); hb_gt_Add_keymap( K_ALT_K, "\033K" ); hb_gt_Add_keymap( K_ALT_L, "\033l" ); - hb_gt_Add_keymap( K_ALT_L, "\033L" ); + hb_gt_Add_keymap( K_ALT_L, "\033L" ); hb_gt_Add_keymap( K_ALT_M, "\033m" ); hb_gt_Add_keymap( K_ALT_M, "\033M" ); hb_gt_Add_keymap( K_ALT_N, "\033n" ); - hb_gt_Add_keymap( K_ALT_N, "\033N" ); + hb_gt_Add_keymap( K_ALT_N, "\033N" ); hb_gt_Add_keymap( K_ALT_O, "\033o" ); hb_gt_Add_keymap( K_ALT_O, "\033O" ); hb_gt_Add_keymap( K_ALT_P, "\033p" ); - hb_gt_Add_keymap( K_ALT_P, "\033P" ); + hb_gt_Add_keymap( K_ALT_P, "\033P" ); hb_gt_Add_keymap( K_ALT_Q, "\033q" ); - hb_gt_Add_keymap( K_ALT_Q, "\033Q" ); + hb_gt_Add_keymap( K_ALT_Q, "\033Q" ); hb_gt_Add_keymap( K_ALT_R, "\033r" ); - hb_gt_Add_keymap( K_ALT_R, "\033R" ); + hb_gt_Add_keymap( K_ALT_R, "\033R" ); hb_gt_Add_keymap( K_ALT_S, "\033s" ); - hb_gt_Add_keymap( K_ALT_S, "\033S" ); + hb_gt_Add_keymap( K_ALT_S, "\033S" ); hb_gt_Add_keymap( K_ALT_T, "\033t" ); - hb_gt_Add_keymap( K_ALT_T, "\033T" ); + hb_gt_Add_keymap( K_ALT_T, "\033T" ); hb_gt_Add_keymap( K_ALT_U, "\033u" ); - hb_gt_Add_keymap( K_ALT_U, "\033U" ); + hb_gt_Add_keymap( K_ALT_U, "\033U" ); hb_gt_Add_keymap( K_ALT_V, "\033v" ); - hb_gt_Add_keymap( K_ALT_V, "\033V" ); + hb_gt_Add_keymap( K_ALT_V, "\033V" ); hb_gt_Add_keymap( K_ALT_W, "\033w" ); hb_gt_Add_keymap( K_ALT_W, "\033W" ); hb_gt_Add_keymap( K_ALT_X, "\033x" ); @@ -265,7 +256,7 @@ void hb_gt_Init( int iFilenoStdin, int iFilenoStdout, int iFilenoStderr ) hb_gt_Add_keymap( K_ALT_0, "\0330" ); hb_gt_Add_keymap( K_ALT_ENTER, "\033\n" ); hb_gt_Add_keymap( K_ALT_EQUALS, "\033=" ); - + } void hb_gt_Exit( void ) @@ -275,7 +266,7 @@ void hb_gt_Exit( void ) noraw(); refresh(); endwin(); - + if( s_keymap_table ) { struct key_map_struc *tmp = s_keymap_table; @@ -306,7 +297,7 @@ int hb_gt_ReadKey( HB_inkey_enum eventmask ) key_waiting = -1; /* the last character was retrieved */ return ch; } - + ch = getch(); if( ch == ERR ) ch = 0; @@ -321,7 +312,7 @@ int hb_gt_ReadKey( HB_inkey_enum eventmask ) { struct key_map_struc *tmp = s_keymap_table; int i = 0; - + key_codes[ 0 ] = ch; while( ( ch = getch() ) != ERR && i <= HB_MAX_KEYMAP_CHARS ) key_codes[ ++i ] = ch; @@ -336,9 +327,9 @@ int hb_gt_ReadKey( HB_inkey_enum eventmask ) tmp = NULL; } else - tmp = tmp->Next; + tmp = tmp->Next; } - + if( ch == 0 ) { /* keymap not found */ @@ -483,6 +474,16 @@ void hb_gt_SetCursorStyle( USHORT uiStyle ) curs_set( 1 ); } +void hb_gt_xPutch( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_xPutch(%hu, %hu, %d, %i)", uiRow, uiCol, (int) byAttr, byChar)); + + move( uiRow, uiCol ); + addch( byChar | s_alternate_char_set | s_attribmap_table[ byAttr ] ); + if( s_uiDispCount == 0 ) + refresh(); +} + void hb_gt_Puts( USHORT uiRow, USHORT uiCol, BYTE byAttr, @@ -495,7 +496,7 @@ void hb_gt_Puts( USHORT uiRow, HB_TRACE(HB_TR_DEBUG, ("hb_gt_Puts(%hu, %hu, %d, %p, %lu)", uiRow, uiCol, (int) byAttr, pbyStr, ulLen)); attr = s_alternate_char_set | s_attribmap_table[ byAttr ]; - move( uiRow, uiCol ); + move( uiRow, uiCol ); for( i = 0; i < ulLen; ++i ) addch( pbyStr[ i ] | attr ); if( s_uiDispCount == 0 ) @@ -515,7 +516,7 @@ void hb_gt_GetText( USHORT uiTop, { int i; chtype *pBuffer = (chtype *)pbyDst; - + HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetText(%hu, %hu, %hu, %hu, %p)", uiTop, uiLeft, uiBottom, uiRight, pbyDst)); if( s_uiDispCount == 0 ) @@ -537,7 +538,7 @@ void hb_gt_PutText( USHORT uiTop, { int Cols; chtype *pBuffer = (chtype *)pbySrc; - + HB_TRACE(HB_TR_DEBUG, ("hb_gt_PutText(%hu, %hu, %hu, %hu, %p)", uiTop, uiLeft, uiBottom, uiRight, pbySrc)); Cols = uiRight - uiLeft + 1; @@ -560,7 +561,7 @@ void hb_gt_SetAttribute( USHORT uiTop, int Count = uiRight - uiLeft + 1; int newAttr = s_attribmap_table[ byAttr ]; short newColor; - + HB_TRACE(HB_TR_DEBUG, ("hb_gt_SetAttribute(%hu, %hu, %hu, %hu, %d)", uiTop, uiLeft, uiBottom, uiRight, (int) byAttr)); newColor = PAIR_NUMBER( newAttr ); @@ -591,21 +592,21 @@ void hb_gt_Scroll( USHORT uiTop, wclear( subw ); touchwin( stdscr ); wrefresh( subw ); - delwin( subw ); + delwin( subw ); } else { if( iRows != 0 ) { WINDOW *subw; - + subw = subwin( stdscr, uiBottom-uiTop+1, uiRight-uiLeft+1, uiTop, uiLeft ); wbkgdset( subw, ' ' | s_attribmap_table[ byAttr ] ); scrollok( subw, TRUE ); wscrl( subw, iRows ); delwin( subw ); } - + if( iCols != 0 ) { chtype *pScreen, *pTmp; @@ -615,11 +616,11 @@ void hb_gt_Scroll( USHORT uiTop, int newAttr; refresh(); - + RowCount = uiBottom - uiTop + 1; ColCount = uiRight - uiLeft + 1; newAttr = ' ' | s_attribmap_table[ byAttr ]; - + memsize = hb_gt_RectSize( RowCount, ColCount ); pScreen = (chtype *) hb_xgrab( memsize ); hb_gt_GetText( uiTop, uiLeft, uiBottom, uiRight, (BYTE *)pScreen ); @@ -627,7 +628,7 @@ void hb_gt_Scroll( USHORT uiTop, if( iCols > 0 ) { pTmp = pScreen; - for( i=0; i=iCols; j-- ) pTmp[ j ] = pTmp[ j-1 ]; @@ -639,9 +640,9 @@ void hb_gt_Scroll( USHORT uiTop, else { int ColMove = ColCount + iCols; - + pTmp = pScreen; - for( i=0; ikey_string = key_string; keymap->length = iLength; keymap->Next = NULL; - + if( s_keymap_table ) { struct key_map_struc *tmp = s_keymap_table; @@ -789,13 +778,13 @@ static void hb_gt_Add_keymap( int InkeyCode, char *key_string ) } else s_keymap_table = keymap; - } + } } static void hb_gt_Add_terminfo_keymap( int InkeyCode, char *capname ) { char * code; - + code = tigetstr( capname ); if( (code != NULL) && (code != (char *)-1) ) { @@ -803,3 +792,170 @@ static void hb_gt_Add_terminfo_keymap( int InkeyCode, char *capname ) } } +void hb_gt_Replicate( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar, ULONG nLength ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%hu, %hu, %i, %i, %lu)", uiRow, uiCol, byAttr, byChar, nLength)); + + { + while( nLength-- ) + hb_gt_xPutch( uiRow, uiCol++, byAttr, byChar ); + } +} + +USHORT hb_gt_Box( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, + BYTE *szBox, BYTE byAttr ) +{ + USHORT uiRow; + USHORT uiCol; + USHORT uiHeight; + USHORT uiWidth; + + /* Ensure that box is drawn from top left to bottom right. */ + if( uiTop > uiBottom ) + { + USHORT tmp = uiTop; + uiTop = uiBottom; + uiBottom = tmp; + } + if( uiLeft > uiRight ) + { + USHORT tmp = uiLeft; + uiLeft = uiRight; + uiRight = tmp; + } + + if( s_under_xterm ) + { + /* enable temporarily for box drawing + NOTE: under xterm characcters with ASCII code 96 - 124 are + used for special characters + */ + s_alternate_char_set = A_ALTCHARSET; + } + + uiRow = uiTop; + uiCol = uiLeft; + + /* Draw the box or line as specified */ + uiHeight = uiBottom - uiTop + 1; + uiWidth = uiRight - uiLeft + 1; + + hb_gt_DispBegin(); + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiCol, byAttr, szBox[ 0 ] ); /* Upper left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight ) + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 1 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Top line */ + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 2 ] ); /* Upper right corner */ + + if( szBox[ 8 ] && uiHeight > 2 && uiWidth > 2 ) + { + for( uiRow = uiTop + 1; uiRow < uiBottom; uiRow++ ) + { + uiCol = uiLeft; + hb_gt_xPutch( uiRow, uiCol++, byAttr, szBox[ 7 ] ); /* Left side */ + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 8 ], uiRight - uiLeft - 1 ); /* Fill */ + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + else + { + for( uiRow = ( uiWidth > 1 ? uiTop + 1 : uiTop ); uiRow < ( uiWidth > 1 ? uiBottom : uiBottom + 1 ); uiRow++ ) + { + hb_gt_xPutch( uiRow, uiLeft, byAttr, szBox[ 7 ] ); /* Left side */ + if( uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + + if( uiHeight > 1 && uiWidth > 1 ) + { + hb_gt_xPutch( uiBottom, uiLeft, byAttr, szBox[ 6 ] ); /* Bottom left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight && uiHeight > 1 ) + hb_gt_Replicate( uiBottom, uiCol, byAttr, szBox[ 5 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Bottom line */ + + hb_gt_xPutch( uiBottom, uiRight, byAttr, szBox[ 4 ] ); /* Bottom right corner */ + } + + hb_gt_DispEnd(); + + if( s_under_xterm ) + { + s_alternate_char_set = 0; /* restore default setting */ + } + return 0; +} + +USHORT hb_gt_BoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + if( s_under_xterm ) + { + /* Under xterm use hard-coded box drawing characters */ + pbyFrame = s_xTermBox; + s_alternate_char_set = A_ALTCHARSET; + } + hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); + if( s_under_xterm ) + { + s_alternate_char_set = 0; /* restore default setting */ + } + return 0; +} + +USHORT hb_gt_BoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + if( s_under_xterm ) + { + /* Under xterm use hard-coded box drawing characters */ + pbyFrame = s_xTermBox; + s_alternate_char_set = A_ALTCHARSET; + } + hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); + if( s_under_xterm ) + { + s_alternate_char_set = 0; /* restore default setting */ + } + return 0; +} + +USHORT hb_gt_HorizLine( USHORT uiRow, USHORT uiLeft, USHORT uiRight, BYTE byChar, BYTE byAttr ) +{ + if( s_under_xterm ) + byChar = ACS_HLINE; + + if( uiLeft < uiRight ) + mvhline( uiRow, uiLeft, byChar | A_ALTCHARSET | s_attribmap_table[ byAttr ], + uiRight - uiLeft + 1 ); + else + mvhline( uiRow, uiRight, byChar | A_ALTCHARSET | s_attribmap_table[ byAttr ], + uiLeft - uiRight + 1 ); + return 0; +} + +USHORT hb_gt_VertLine( USHORT uiCol, USHORT uiTop, USHORT uiBottom, BYTE byChar, BYTE byAttr ) +{ + USHORT uRow; + + if( uiTop <= uiBottom ) + uRow = uiTop; + else + { + uRow = uiBottom; + uiBottom = uiTop; + } + + if( s_under_xterm ) + byChar = ACS_VLINE; + mvvline( uRow, uiCol, byChar | A_ALTCHARSET | s_attribmap_table[ byAttr ], + uiBottom - uRow + 1 ); + + return 0; +} diff --git a/harbour/source/rtl/gtdos/gtdos.c b/harbour/source/rtl/gtdos/gtdos.c index fdd7e4527f..c4a59c9492 100644 --- a/harbour/source/rtl/gtdos/gtdos.c +++ b/harbour/source/rtl/gtdos/gtdos.c @@ -585,13 +585,17 @@ static void hb_gt_xGetXY( USHORT cRow, USHORT cCol, BYTE * attr, BYTE * ch ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_xGetXY(%hu, %hu, %p, %p", cRow, cCol, ch, attr)); -#if defined(__DJGPP__) +#if defined(__DJGPP__TEXT) { short ch_attr; gettext( cCol + 1, cRow + 1, cCol + 1, cRow + 1, &ch_attr ); *ch = ch_attr >> 8; *attr = ch_attr & 0xFF; } +#elif defined(__DJGPP__) + { + ScreenGetChar( (int *)ch, (int *)attr, cCol, cRow ); + } #else { char FAR *p; @@ -606,18 +610,20 @@ void hb_gt_xPutch( USHORT cRow, USHORT cCol, BYTE attr, BYTE ch ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_xPutch(%hu, %hu, %d, %d", cRow, cCol, (int) attr, (int) ch)); -#if defined(__DJGPP__) +#if defined(__DJGPP__TEXT) { long ch_attr; ch_attr = ( ch << 8 ) | attr; puttext( cCol + 1, cRow + 1, cCol + 1, cRow + 1, &ch_attr ); } +#elif defined(__DJGPP) + { + ScreenPutChar( ch, attr, cCol, cRow ); + } #else { - char FAR * p; - p = hb_gt_ScreenPtr( cRow, cCol ); - *p = ch; - *( p + 1 ) = attr; + USHORT FAR * p = (USHORT FAR *) hb_gt_ScreenPtr( cRow, cCol ); + *p = (attr << 8) + ch; } #endif } @@ -626,7 +632,7 @@ void hb_gt_Puts( USHORT cRow, USHORT cCol, BYTE attr, BYTE *str, ULONG len ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_Puts(%hu, %hu, %d, %p, %lu", cRow, cCol, (int) attr, str, len)); -#if defined(__DJGPP__) +#if defined(__DJGPP__TEXT) { int i; int bottom, left, right, top; @@ -666,17 +672,22 @@ void hb_gt_Puts( USHORT cRow, USHORT cCol, BYTE attr, BYTE *str, ULONG len ) puttext( left + 1, top + 1, right + 1, bottom + 1, ch_attr ); hb_xfree( ch_attr ); } +#elif defined(__DJGPP__) + { + int i; + for( i=0; i width - 1 ) + { + /* + * Calculate end row position and the remainder size for the + * end column adjust. + */ + bottom += ( i / width ); + i = i % width; + } + right += i; + if( right > width - 1 ) + { + /* Column movement overflows into next row */ + bottom++; + right -= width; + } + puttext( left + 1, top + 1, right + 1, bottom + 1, ch_attr ); + hb_xfree( ch_attr ); + } +#elif defined(__DJGPP__) + { + while( nLength-- ) + ScreenPutChar( byChar, byAttr, uiCol++, uiRow ); + } +#else + { + USHORT FAR *p; + USHORT byte = (byAttr << 8) + byChar; + + p = (USHORT FAR *) hb_gt_ScreenPtr( uiRow, uiCol ); + while( nLength-- ) + { + *p++ = byte; + } + } +#endif +} + +USHORT hb_gt_Box( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, + BYTE *szBox, BYTE byAttr ) +{ + USHORT uiRow; + USHORT uiCol; + USHORT uiHeight; + USHORT uiWidth; + + /* Ensure that box is drawn from top left to bottom right. */ + if( uiTop > uiBottom ) + { + USHORT tmp = uiTop; + uiTop = uiBottom; + uiBottom = tmp; + } + if( uiLeft > uiRight ) + { + USHORT tmp = uiLeft; + uiLeft = uiRight; + uiRight = tmp; + } + + uiRow = uiTop; + uiCol = uiLeft; + + /* Draw the box or line as specified */ + uiHeight = uiBottom - uiTop + 1; + uiWidth = uiRight - uiLeft + 1; + + hb_gt_DispBegin(); + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiCol, byAttr, szBox[ 0 ] ); /* Upper left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight ) + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 1 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Top line */ + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 2 ] ); /* Upper right corner */ + + if( szBox[ 8 ] && uiHeight > 2 && uiWidth > 2 ) + { + for( uiRow = uiTop + 1; uiRow < uiBottom; uiRow++ ) + { + uiCol = uiLeft; + hb_gt_xPutch( uiRow, uiCol++, byAttr, szBox[ 7 ] ); /* Left side */ + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 8 ], uiRight - uiLeft - 1 ); /* Fill */ + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + else + { + for( uiRow = ( uiWidth > 1 ? uiTop + 1 : uiTop ); uiRow < ( uiWidth > 1 ? uiBottom : uiBottom + 1 ); uiRow++ ) + { + hb_gt_xPutch( uiRow, uiLeft, byAttr, szBox[ 7 ] ); /* Left side */ + if( uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + + if( uiHeight > 1 && uiWidth > 1 ) + { + hb_gt_xPutch( uiBottom, uiLeft, byAttr, szBox[ 6 ] ); /* Bottom left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight && uiHeight > 1 ) + hb_gt_Replicate( uiBottom, uiCol, byAttr, szBox[ 5 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Bottom line */ + + hb_gt_xPutch( uiBottom, uiRight, byAttr, szBox[ 4 ] ); /* Bottom right corner */ + } + + hb_gt_DispEnd(); + + return 0; +} + +USHORT hb_gt_BoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_BoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_HorizLine( USHORT uiRow, USHORT uiLeft, USHORT uiRight, BYTE byChar, BYTE byAttr ) +{ + if( uiLeft < uiRight ) + hb_gt_Replicate( uiRow, uiLeft, byAttr, byChar, uiRight - uiLeft + 1 ); + else + hb_gt_Replicate( uiRow, uiRight, byAttr, byChar, uiLeft - uiRight + 1 ); + return 0; +} + +USHORT hb_gt_VertLine( USHORT uiCol, USHORT uiTop, USHORT uiBottom, BYTE byChar, BYTE byAttr ) +{ + USHORT uRow; + + if( uiTop <= uiBottom ) + uRow = uiTop; + else + { + uRow = uiBottom; + uiBottom = uiTop; + } + while( uRow <= uiBottom ) + hb_gt_xPutch( uRow++, uiCol, byAttr, byChar ); + return 0; +} diff --git a/harbour/source/rtl/gtos2/gtos2.c b/harbour/source/rtl/gtos2/gtos2.c index a4ec04773e..1407a38818 100644 --- a/harbour/source/rtl/gtos2/gtos2.c +++ b/harbour/source/rtl/gtos2/gtos2.c @@ -599,13 +599,12 @@ static void hb_gt_xGetXY( USHORT cRow, USHORT cCol, BYTE * attr, BYTE * ch ) void hb_gt_xPutch( USHORT cRow, USHORT cCol, BYTE attr, BYTE ch ) { - char * p; - HB_TRACE(HB_TR_DEBUG, ("hb_gt_xPutch(%hu, %hu, %d, %d", cRow, cCol, (int) attr, (int) ch)); - p = hb_gt_ScreenPtr( cRow, cCol ); - *p = ch; - *( p + 1 ) = attr; + { + USHORT FAR * p = (USHORT FAR *) hb_gt_ScreenPtr( cRow, cCol ); + *p = (attr << 8) + ch; + } } @@ -614,13 +613,13 @@ void hb_gt_Puts( USHORT usRow, USHORT usCol, BYTE attr, BYTE * str, ULONG len ) HB_TRACE(HB_TR_DEBUG, ("hb_gt_Puts(%hu, %hu, %d, %p, %lu)", usRow, usCol, (int) attr, str, len)); if(s_uiDispCount > 0) { - char *p; - int i; + USHORT FAR *p; + register USHORT byAttr = attr << 8; - p = hb_gt_ScreenPtr( usRow, usCol ); - for( i = 0; i < len; i++ ) { - *p++ = *str++; - *p++ = attr; + p = (USHORT FAR *) hb_gt_ScreenPtr( usRow, usCol ); + while( len-- ) + { + *p++ = byAttr + (*str++); } } else { VioWrtCharStrAtt( ( char * ) str, ( USHORT ) len, usRow, usCol, ( BYTE * ) &attr, 0 ); @@ -756,20 +755,6 @@ BOOL hb_gt_SetMode( USHORT uiRows, USHORT uiCols ) return ( BOOL ) VioSetMode( &vi, 0 ); /* 0 = Ok, other = Fail */ } -void hb_gt_Replicate( BYTE c, ULONG ulLen ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%d, %lu)", (int) c, ulLen)); - - /* TODO: this will write character c nlength times to the screen. - Note that it is not used yet - If there is no native function that supports this, it is - already handled in a generic way by higher level functions. - */ - - c = ' '; - ulLen = 0; -} - BOOL hb_gt_GetBlink() { /* Chen Kedem */ @@ -833,3 +818,132 @@ USHORT hb_gt_DispCount() { return s_uiDispCount; } + +void hb_gt_Replicate( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar, ULONG nLength ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%hu, %hu, %i, %i, %lu)", uiRow, uiCol, byAttr, byChar, nLength)); + { + USHORT FAR *p; + USHORT byte = (byAttr << 8) + byChar; + + p = (USHORT FAR *) hb_gt_ScreenPtr( uiRow, uiCol ); + while( nLength-- ) + { + *p++ = byte; + } + } +} + +USHORT hb_gt_Box( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, + BYTE *szBox, BYTE byAttr ) +{ + USHORT uiRow; + USHORT uiCol; + USHORT uiHeight; + USHORT uiWidth; + + /* Ensure that box is drawn from top left to bottom right. */ + if( uiTop > uiBottom ) + { + USHORT tmp = uiTop; + uiTop = uiBottom; + uiBottom = tmp; + } + if( uiLeft > uiRight ) + { + USHORT tmp = uiLeft; + uiLeft = uiRight; + uiRight = tmp; + } + + uiRow = uiTop; + uiCol = uiLeft; + + /* Draw the box or line as specified */ + uiHeight = uiBottom - uiTop + 1; + uiWidth = uiRight - uiLeft + 1; + + hb_gt_DispBegin(); + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiCol, byAttr, szBox[ 0 ] ); /* Upper left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight ) + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 1 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Top line */ + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 2 ] ); /* Upper right corner */ + + if( szBox[ 8 ] && uiHeight > 2 && uiWidth > 2 ) + { + for( uiRow = uiTop + 1; uiRow < uiBottom; uiRow++ ) + { + uiCol = uiLeft; + hb_gt_xPutch( uiRow, uiCol++, byAttr, szBox[ 7 ] ); /* Left side */ + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 8 ], uiRight - uiLeft - 1 ); /* Fill */ + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + else + { + for( uiRow = ( uiWidth > 1 ? uiTop + 1 : uiTop ); uiRow < ( uiWidth > 1 ? uiBottom : uiBottom + 1 ); uiRow++ ) + { + hb_gt_xPutch( uiRow, uiLeft, byAttr, szBox[ 7 ] ); /* Left side */ + if( uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + + if( uiHeight > 1 && uiWidth > 1 ) + { + hb_gt_xPutch( uiBottom, uiLeft, byAttr, szBox[ 6 ] ); /* Bottom left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight && uiHeight > 1 ) + hb_gt_Replicate( uiBottom, uiCol, byAttr, szBox[ 5 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Bottom line */ + + hb_gt_xPutch( uiBottom, uiRight, byAttr, szBox[ 4 ] ); /* Bottom right corner */ + } + + hb_gt_DispEnd(); + + return 0; +} + +USHORT hb_gt_BoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_BoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_HorizLine( USHORT uiRow, USHORT uiLeft, USHORT uiRight, BYTE byChar, BYTE byAttr ) +{ + if( uiLeft < uiRight ) + hb_gt_Replicate( uiRow, uiLeft, byAttr, byChar, uiRight - uiLeft + 1 ); + else + hb_gt_Replicate( uiRow, uiRight, byAttr, byChar, uiLeft - uiRight + 1 ); + return 0; +} + +USHORT hb_gt_VertLine( USHORT uiCol, USHORT uiTop, USHORT uiBottom, BYTE byChar, BYTE byAttr ) +{ + USHORT uRow; + + if( uiTop <= uiBottom ) + uRow = uiTop; + else + { + uRow = uiBottom; + uiBottom = uiTop; + } + while( uRow <= uiBottom ) + hb_gt_xPutch( uRow++, uiCol, byAttr, byChar ); + return 0; +} diff --git a/harbour/source/rtl/gtpca/gtpca.c b/harbour/source/rtl/gtpca/gtpca.c index 30bc8cb4e0..087820039f 100644 --- a/harbour/source/rtl/gtpca/gtpca.c +++ b/harbour/source/rtl/gtpca/gtpca.c @@ -195,21 +195,21 @@ int hb_gt_ReadKey( HB_inkey_enum eventmask ) BOOL hb_gt_IsColor( void ) { - HB_TRACE(HB_TR_DEBUG, ("hb_gt_IsColor()")); + HB_TRACE(HB_TR_DEBUG, ("hb_gt_IsColor()")); /* TODO: */ return s_bColor; } USHORT hb_gt_GetScreenWidth( void ) { - HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetScreenWidth()")); + HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetScreenWidth()")); /* TODO: */ return s_usMaxCol + 1; } USHORT hb_gt_GetScreenHeight( void ) { - HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetScreenHeight()")); + HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetScreenHeight()")); /* TODO: */ return s_usMaxRow + 1; } @@ -297,6 +297,28 @@ void hb_gt_SetCursorStyle( USHORT style ) HB_SYMBOL_UNUSED( style ); } +void hb_gt_xPutch( USHORT usRow, USHORT usCol, BYTE attr, BYTE byChar ) +{ + char tmp[ 2 ]; + HB_TRACE(HB_TR_DEBUG, ("hb_gt_xPutch(%hu, %hu, %d, %i)", usRow, usCol, (int) attr, byChar)); + + /* TOFIX: add correct support for a single byte instead of a string + */ + tmp[ 0 ] = byChar; + tmp[ 1 ] = '\0'; + + /* Disable line wrap, set the new cursor position, send the string, then + enable line wrap (for OUTSTD() and OUTERR() ) */ + hb_gt_AnsiSetAttributes( attr ); + fprintf( stdout, "\x1B[=7l\x1B[%d;%dH%s\x1B[=7h", usRow + 1, usCol + 1, tmp ); + + /* Restore whatever used to be at the termination position */ + /* Update the cursor position */ + s_usRow = usRow; + s_usCol = usCol + 1; + if( s_usCol > s_usMaxCol ) s_usCol = s_usMaxCol; +} + void hb_gt_Puts( USHORT usRow, USHORT usCol, BYTE attr, BYTE * str, ULONG len ) { /* Because Clipper strings don't have to be null terminated, add a null @@ -383,18 +405,6 @@ BOOL hb_gt_SetMode( USHORT uiRows, USHORT uiCols ) return 0; /* 0 = Ok, other = Fail */ } -void hb_gt_Replicate( BYTE c, ULONG ulLen ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%d, %lu)", (int) c, ulLen) ); - HB_SYMBOL_UNUSED( c ); - HB_SYMBOL_UNUSED( ulLen ); - /* TODO: this will write character c nlength times to the screen. - Note that it is not used yet - If there is no native function that supports this, it is - already handled in a generic way by higher level functions. - */ -} - BOOL hb_gt_GetBlink() { HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetBlink()")); @@ -428,3 +438,128 @@ USHORT hb_gt_DispCount() { return s_uiDispCount; } + + +void hb_gt_Replicate( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar, ULONG nLength ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%hu, %hu, %i, %i, %lu)", uiRow, uiCol, byAttr, byChar, nLength)); + + { + while( nLength-- ) + hb_gt_xPutch( uiRow, uiCol++, byAttr, byChar ); + } +} + +USHORT hb_gt_Box( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, + BYTE *szBox, BYTE byAttr ) +{ + USHORT uiRow; + USHORT uiCol; + USHORT uiHeight; + USHORT uiWidth; + + /* Ensure that box is drawn from top left to bottom right. */ + if( uiTop > uiBottom ) + { + USHORT tmp = uiTop; + uiTop = uiBottom; + uiBottom = tmp; + } + if( uiLeft > uiRight ) + { + USHORT tmp = uiLeft; + uiLeft = uiRight; + uiRight = tmp; + } + + uiRow = uiTop; + uiCol = uiLeft; + + /* Draw the box or line as specified */ + uiHeight = uiBottom - uiTop + 1; + uiWidth = uiRight - uiLeft + 1; + + hb_gt_DispBegin(); + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiCol, byAttr, szBox[ 0 ] ); /* Upper left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight ) + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 1 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Top line */ + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 2 ] ); /* Upper right corner */ + + if( szBox[ 8 ] && uiHeight > 2 && uiWidth > 2 ) + { + for( uiRow = uiTop + 1; uiRow < uiBottom; uiRow++ ) + { + uiCol = uiLeft; + hb_gt_xPutch( uiRow, uiCol++, byAttr, szBox[ 7 ] ); /* Left side */ + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 8 ], uiRight - uiLeft - 1 ); /* Fill */ + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + else + { + for( uiRow = ( uiWidth > 1 ? uiTop + 1 : uiTop ); uiRow < ( uiWidth > 1 ? uiBottom : uiBottom + 1 ); uiRow++ ) + { + hb_gt_xPutch( uiRow, uiLeft, byAttr, szBox[ 7 ] ); /* Left side */ + if( uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + + if( uiHeight > 1 && uiWidth > 1 ) + { + hb_gt_xPutch( uiBottom, uiLeft, byAttr, szBox[ 6 ] ); /* Bottom left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight && uiHeight > 1 ) + hb_gt_Replicate( uiBottom, uiCol, byAttr, szBox[ 5 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Bottom line */ + + hb_gt_xPutch( uiBottom, uiRight, byAttr, szBox[ 4 ] ); /* Bottom right corner */ + } + + hb_gt_DispEnd(); + + return 0; +} + +USHORT hb_gt_BoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_BoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_HorizLine( USHORT uiRow, USHORT uiLeft, USHORT uiRight, BYTE byChar, BYTE byAttr ) +{ + if( uiLeft < uiRight ) + hb_gt_Replicate( uiRow, uiLeft, byAttr, byChar, uiRight - uiLeft + 1 ); + else + hb_gt_Replicate( uiRow, uiRight, byAttr, byChar, uiLeft - uiRight + 1 ); + return 0; +} + +USHORT hb_gt_VertLine( USHORT uiCol, USHORT uiTop, USHORT uiBottom, BYTE byChar, BYTE byAttr ) +{ + USHORT uRow; + + if( uiTop <= uiBottom ) + uRow = uiTop; + else + { + uRow = uiBottom; + uiBottom = uiTop; + } + while( uRow <= uiBottom ) + hb_gt_xPutch( uRow++, uiCol, byAttr, byChar ); + return 0; +} diff --git a/harbour/source/rtl/gtsln/gtsln.c b/harbour/source/rtl/gtsln/gtsln.c index 871c2b6890..b427de2781 100644 --- a/harbour/source/rtl/gtsln/gtsln.c +++ b/harbour/source/rtl/gtsln/gtsln.c @@ -228,6 +228,21 @@ void hb_gt_SetCursorStyle( USHORT uiStyle ) } } +void hb_gt_xPutch( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_xPutch(%hu, %hu, %d, %i)", uiRow, uiCol, (int) byAttr, byChar)); + { + BYTE tmp[ 2 ]; + + /* TOFIX: add correct support for a single byte instead of a string + */ + tmp[ 0 ] = byChar; + tmp[ 1 ] = 0; + SLsmg_gotorc(uiRow, uiCol); + SLsmg_write_nchars(tmp, 1); + } +} + void hb_gt_Puts( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE * pbyStr, ULONG ulLen ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_Puts(%hu, %hu, %d, %p, %lu)", uiRow, uiCol, (int) byAttr, pbyStr, ulLen)); @@ -325,20 +340,6 @@ BOOL hb_gt_SetMode( USHORT uiRows, USHORT uiCols ) } -void hb_gt_Replicate( BYTE byChar, ULONG ulLen ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%d, %lu)", (int) byChar, ulLen)); - - /* TODO: this will write character c nlength times to the screen. - Note that it is not used yet - If there is no native function that supports this, it is - already handled in a generic way by higher level functions. - */ - - HB_SYMBOL_UNUSED( byChar ); - HB_SYMBOL_UNUSED( ulLen ); -} - BOOL hb_gt_GetBlink() { HB_TRACE(HB_TR_DEBUG, ("hb_gt_GetBlink()")); @@ -378,3 +379,127 @@ USHORT hb_gt_DispCount() { return s_uiDispCount; } + +void hb_gt_Replicate( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar, ULONG nLength ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%hu, %hu, %i, %i, %lu)", uiRow, uiCol, byAttr, byChar, nLength)); + + { + while( nLength-- ) + hb_gt_xPutch( uiRow, uiCol++, byAttr, byChar ); + } +} + +USHORT hb_gt_Box( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, + BYTE *szBox, BYTE byAttr ) +{ + USHORT uiRow; + USHORT uiCol; + USHORT uiHeight; + USHORT uiWidth; + + /* Ensure that box is drawn from top left to bottom right. */ + if( uiTop > uiBottom ) + { + USHORT tmp = uiTop; + uiTop = uiBottom; + uiBottom = tmp; + } + if( uiLeft > uiRight ) + { + USHORT tmp = uiLeft; + uiLeft = uiRight; + uiRight = tmp; + } + + uiRow = uiTop; + uiCol = uiLeft; + + /* Draw the box or line as specified */ + uiHeight = uiBottom - uiTop + 1; + uiWidth = uiRight - uiLeft + 1; + + hb_gt_DispBegin(); + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiCol, byAttr, szBox[ 0 ] ); /* Upper left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight ) + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 1 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Top line */ + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 2 ] ); /* Upper right corner */ + + if( szBox[ 8 ] && uiHeight > 2 && uiWidth > 2 ) + { + for( uiRow = uiTop + 1; uiRow < uiBottom; uiRow++ ) + { + uiCol = uiLeft; + hb_gt_xPutch( uiRow, uiCol++, byAttr, szBox[ 7 ] ); /* Left side */ + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 8 ], uiRight - uiLeft - 1 ); /* Fill */ + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + else + { + for( uiRow = ( uiWidth > 1 ? uiTop + 1 : uiTop ); uiRow < ( uiWidth > 1 ? uiBottom : uiBottom + 1 ); uiRow++ ) + { + hb_gt_xPutch( uiRow, uiLeft, byAttr, szBox[ 7 ] ); /* Left side */ + if( uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + + if( uiHeight > 1 && uiWidth > 1 ) + { + hb_gt_xPutch( uiBottom, uiLeft, byAttr, szBox[ 6 ] ); /* Bottom left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight && uiHeight > 1 ) + hb_gt_Replicate( uiBottom, uiCol, byAttr, szBox[ 5 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Bottom line */ + + hb_gt_xPutch( uiBottom, uiRight, byAttr, szBox[ 4 ] ); /* Bottom right corner */ + } + + hb_gt_DispEnd(); + + return 0; +} + +USHORT hb_gt_BoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_BoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_HorizLine( USHORT uiRow, USHORT uiLeft, USHORT uiRight, BYTE byChar, BYTE byAttr ) +{ + if( uiLeft < uiRight ) + hb_gt_Replicate( uiRow, uiLeft, byAttr, byChar, uiRight - uiLeft + 1 ); + else + hb_gt_Replicate( uiRow, uiRight, byAttr, byChar, uiLeft - uiRight + 1 ); + return 0; +} + +USHORT hb_gt_VertLine( USHORT uiCol, USHORT uiTop, USHORT uiBottom, BYTE byChar, BYTE byAttr ) +{ + USHORT uRow; + + if( uiTop <= uiBottom ) + uRow = uiTop; + else + { + uRow = uiBottom; + uiBottom = uiTop; + } + while( uRow <= uiBottom ) + hb_gt_xPutch( uRow++, uiCol, byAttr, byChar ); + return 0; +} diff --git a/harbour/source/rtl/gtstd/gtstd.c b/harbour/source/rtl/gtstd/gtstd.c index e18407095a..d8cc624ae3 100644 --- a/harbour/source/rtl/gtstd/gtstd.c +++ b/harbour/source/rtl/gtstd/gtstd.c @@ -84,7 +84,7 @@ void hb_gt_Exit( void ) int hb_gt_ReadKey( HB_inkey_enum eventmask ) { int ch; - + HB_TRACE(HB_TR_DEBUG, ("hb_gt_ReadKey(%d)", (int) eventmask)); HB_SYMBOL_UNUSED( eventmask ); @@ -230,6 +230,18 @@ void hb_gt_SetCursorStyle( USHORT uiCursorStyle ) s_uiCursorStyle = uiCursorStyle; } +void hb_gt_xPutch( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_xPutch(%hu, %hu, %d, %i)", uiRow, uiCol, (int) byAttr, byAttr)); + + /* TODO: */ + + HB_SYMBOL_UNUSED( uiRow ); + HB_SYMBOL_UNUSED( uiCol ); + HB_SYMBOL_UNUSED( byAttr ); + HB_SYMBOL_UNUSED( byChar ); +} + void hb_gt_Puts( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE * pbyStr, ULONG ulLen ) { HB_TRACE(HB_TR_DEBUG, ("hb_gt_Puts(%hu, %hu, %d, %p, %lu)", uiRow, uiCol, (int) byAttr, pbyStr, ulLen)); @@ -334,15 +346,6 @@ BOOL hb_gt_SetMode( USHORT uiMaxRow, USHORT uiMaxCol ) return FALSE; } -void hb_gt_Replicate( BYTE byChar, ULONG ulLen ) -{ - HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%d, %lu)", (int) byChar, ulLen)); - - /* TODO: */ - - HB_SYMBOL_UNUSED( byChar ); - HB_SYMBOL_UNUSED( ulLen ); -} BOOL hb_gt_GetBlink() { @@ -488,3 +491,127 @@ USHORT hb_gt_DispCount() { return s_uiDispCount; } + +void hb_gt_Replicate( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar, ULONG nLength ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%hu, %hu, %i, %i, %lu)", uiRow, uiCol, byAttr, byChar, nLength)); + + { + while( nLength-- ) + hb_gt_xPutch( uiRow, uiCol++, byAttr, byChar ); + } +} + +USHORT hb_gt_Box( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, + BYTE *szBox, BYTE byAttr ) +{ + USHORT uiRow; + USHORT uiCol; + USHORT uiHeight; + USHORT uiWidth; + + /* Ensure that box is drawn from top left to bottom right. */ + if( uiTop > uiBottom ) + { + USHORT tmp = uiTop; + uiTop = uiBottom; + uiBottom = tmp; + } + if( uiLeft > uiRight ) + { + USHORT tmp = uiLeft; + uiLeft = uiRight; + uiRight = tmp; + } + + uiRow = uiTop; + uiCol = uiLeft; + + /* Draw the box or line as specified */ + uiHeight = uiBottom - uiTop + 1; + uiWidth = uiRight - uiLeft + 1; + + hb_gt_DispBegin(); + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiCol, byAttr, szBox[ 0 ] ); /* Upper left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight ) + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 1 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Top line */ + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 2 ] ); /* Upper right corner */ + + if( szBox[ 8 ] && uiHeight > 2 && uiWidth > 2 ) + { + for( uiRow = uiTop + 1; uiRow < uiBottom; uiRow++ ) + { + uiCol = uiLeft; + hb_gt_xPutch( uiRow, uiCol++, byAttr, szBox[ 7 ] ); /* Left side */ + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 8 ], uiRight - uiLeft - 1 ); /* Fill */ + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + else + { + for( uiRow = ( uiWidth > 1 ? uiTop + 1 : uiTop ); uiRow < ( uiWidth > 1 ? uiBottom : uiBottom + 1 ); uiRow++ ) + { + hb_gt_xPutch( uiRow, uiLeft, byAttr, szBox[ 7 ] ); /* Left side */ + if( uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + + if( uiHeight > 1 && uiWidth > 1 ) + { + hb_gt_xPutch( uiBottom, uiLeft, byAttr, szBox[ 6 ] ); /* Bottom left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight && uiHeight > 1 ) + hb_gt_Replicate( uiBottom, uiCol, byAttr, szBox[ 5 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Bottom line */ + + hb_gt_xPutch( uiBottom, uiRight, byAttr, szBox[ 4 ] ); /* Bottom right corner */ + } + + hb_gt_DispEnd(); + + return 0; +} + +USHORT hb_gt_BoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_BoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_HorizLine( USHORT uiRow, USHORT uiLeft, USHORT uiRight, BYTE byChar, BYTE byAttr ) +{ + if( uiLeft < uiRight ) + hb_gt_Replicate( uiRow, uiLeft, byAttr, byChar, uiRight - uiLeft + 1 ); + else + hb_gt_Replicate( uiRow, uiRight, byAttr, byChar, uiLeft - uiRight + 1 ); + return 0; +} + +USHORT hb_gt_VertLine( USHORT uiCol, USHORT uiTop, USHORT uiBottom, BYTE byChar, BYTE byAttr ) +{ + USHORT uRow; + + if( uiTop <= uiBottom ) + uRow = uiTop; + else + { + uRow = uiBottom; + uiBottom = uiTop; + } + while( uRow <= uiBottom ) + hb_gt_xPutch( uRow++, uiCol, byAttr, byChar ); + return 0; +} diff --git a/harbour/source/rtl/gtwin/gtwin.c b/harbour/source/rtl/gtwin/gtwin.c index 1540e60d40..a9f1d58e8e 100644 --- a/harbour/source/rtl/gtwin/gtwin.c +++ b/harbour/source/rtl/gtwin/gtwin.c @@ -798,6 +798,26 @@ void hb_gt_SetCursorStyle( USHORT style ) SetConsoleCursorInfo( s_HActive, &cci ); } +void hb_gt_xPutch( USHORT uiRow, USHORT uiCol, BYTE attr, BYTE byChar ) +{ + DWORD dwWritten; + COORD coord; + char tmp[ 2 ]; + + HB_TRACE(HB_TR_DEBUG, ("hb_gt_xPutch(%hu, %hu, %d, %i)", uiRow, uiCol, (int) attr, byChar)); + + /* TOFIX: add correct support for a single byte instead of a string + */ + tmp[ 0 ] = byChar; + tmp[ 1 ] = '\0'; + + coord.X = ( SHORT ) uiCol; + coord.Y = ( SHORT ) uiRow; + + FillConsoleOutputAttribute( s_HOutput, ( WORD )( attr & 0xFF ), ( DWORD ) 1, coord, &dwWritten ); + WriteConsoleOutputCharacterA( s_HOutput, tmp, 1, coord, &dwWritten ); +} + void hb_gt_Puts( USHORT uiRow, USHORT uiCol, BYTE attr, BYTE * str, ULONG len ) { DWORD dwWritten; @@ -1105,19 +1125,22 @@ BOOL hb_gt_SetMode( USHORT uiRows, USHORT uiCols ) return bRetVal; } -void hb_gt_Replicate( BYTE c, ULONG ulLength ) +void hb_gt_Replicate( USHORT uiRow, USHORT uiCol, BYTE byAttr, BYTE byChar, ULONG ulLength ) { /* ptucker */ - COORD coBuf = { 0, 0 }; + COORD coBuf; DWORD dwWritten; - HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%d, %lu)", (int) c, ulLength)); + HB_TRACE(HB_TR_DEBUG, ("hb_gt_Replicate(%hu, %hu, %i, %i, %lu)", uiRow, uiCol, byAttr, byChar, ulLength)); -/* TODO: This is not used and may be eliminated after further review */ + coBuf.Y = uiRow; + coBuf.X = uiCol; + + FillConsoleOutputAttribute( s_HOutput, ( WORD )( byAttr & 0xFF ), ( DWORD )ulLength, coord, &dwWritten ); FillConsoleOutputCharacter( s_HOutput, /* handle to screen buffer */ - c, /* character to write */ + byChar, /* character to write */ ( DWORD ) ulLength, /* number of cells to write */ coBuf, /* coordinates of first cell */ &dwWritten /* receives actual number written */ @@ -1215,3 +1238,118 @@ USHORT hb_gt_DispCount() { return s_uiDispCount; } + + +USHORT hb_gt_Box( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, + BYTE *szBox, BYTE byAttr ) +{ + USHORT uiRow; + USHORT uiCol; + USHORT uiHeight; + USHORT uiWidth; + + /* Ensure that box is drawn from top left to bottom right. */ + if( uiTop > uiBottom ) + { + USHORT tmp = uiTop; + uiTop = uiBottom; + uiBottom = tmp; + } + if( uiLeft > uiRight ) + { + USHORT tmp = uiLeft; + uiLeft = uiRight; + uiRight = tmp; + } + + uiRow = uiTop; + uiCol = uiLeft; + + /* Draw the box or line as specified */ + uiHeight = uiBottom - uiTop + 1; + uiWidth = uiRight - uiLeft + 1; + + hb_gt_DispBegin(); + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiCol, byAttr, szBox[ 0 ] ); /* Upper left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight ) + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 1 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Top line */ + + if( uiHeight > 1 && uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 2 ] ); /* Upper right corner */ + + if( szBox[ 8 ] && uiHeight > 2 && uiWidth > 2 ) + { + for( uiRow = uiTop + 1; uiRow < uiBottom; uiRow++ ) + { + uiCol = uiLeft; + hb_gt_xPutch( uiRow, uiCol++, byAttr, szBox[ 7 ] ); /* Left side */ + hb_gt_Replicate( uiRow, uiCol, byAttr, szBox[ 8 ], uiRight - uiLeft - 1 ); /* Fill */ + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + else + { + for( uiRow = ( uiWidth > 1 ? uiTop + 1 : uiTop ); uiRow < ( uiWidth > 1 ? uiBottom : uiBottom + 1 ); uiRow++ ) + { + hb_gt_xPutch( uiRow, uiLeft, byAttr, szBox[ 7 ] ); /* Left side */ + if( uiWidth > 1 ) + hb_gt_xPutch( uiRow, uiRight, byAttr, szBox[ 3 ] ); /* Right side */ + } + } + + if( uiHeight > 1 && uiWidth > 1 ) + { + hb_gt_xPutch( uiBottom, uiLeft, byAttr, szBox[ 6 ] ); /* Bottom left corner */ + + uiCol = ( uiHeight > 1 ? uiLeft + 1 : uiLeft ); + + if( uiCol <= uiRight && uiHeight > 1 ) + hb_gt_Replicate( uiBottom, uiCol, byAttr, szBox[ 5 ], uiRight - uiLeft + ( uiHeight > 1 ? -1 : 1 ) ); /* Bottom line */ + + hb_gt_xPutch( uiBottom, uiRight, byAttr, szBox[ 4 ] ); /* Bottom right corner */ + } + + hb_gt_DispEnd(); + + return 0; +} + +USHORT hb_gt_BoxD( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_BoxS( USHORT uiTop, USHORT uiLeft, USHORT uiBottom, USHORT uiRight, BYTE * pbyFrame, BYTE byAttr ) +{ + return hb_gt_Box( uiTop, uiLeft, uiBottom, uiRight, pbyFrame, byAttr ); +} + +USHORT hb_gt_HorizLine( USHORT uiRow, USHORT uiLeft, USHORT uiRight, BYTE byChar, BYTE byAttr ) +{ + if( uiLeft < uiRight ) + hb_gt_Replicate( uiRow, uiLeft, byAttr, byChar, uiRight - uiLeft + 1 ); + else + hb_gt_Replicate( uiRow, uiRight, byAttr, byChar, uiLeft - uiRight + 1 ); + return 0; +} + +USHORT hb_gt_VertLine( USHORT uiCol, USHORT uiTop, USHORT uiBottom, BYTE byChar, BYTE byAttr ) +{ + USHORT uRow; + + if( uiTop <= uiBottom ) + uRow = uiTop; + else + { + uRow = uiBottom; + uiBottom = uiTop; + } + while( uRow <= uiBottom ) + hb_gt_xPutch( uRow++, uiCol, byAttr, byChar ); + return 0; +}