home *** CD-ROM | disk | FTP | other *** search
- /* Copyright T.Kobayashi */
-
- /* 1991 08/17 H.Ogasawara 漢字対応, ライブラリ化 */
- /* 1995 11/29 H.Ogasawara debug */
-
-
-
- #include <stdio.h>
- #include <wlib.h>
-
-
- #define swap( a1, a2 ) { int _w ; _w = a2 ; a2 = a1 ; a1 = _w ; }
-
- static int Ydot= 12;
- static int Xdot= 6;
- static unsigned char **CharBuf;
- static WindowID Cwp;
- static int COLOR= 1;
-
- #define LEFTOFF 0 /* window left offset */
- /*#define COLOR 1 /* reverse color */
-
-
- static void
- DrawSetRegion( buf, x1, x2, y )
- DrawBuf *buf;
- int x1,
- x2,
- y;
- {
- DrawSetLine( buf, LEFTOFF+x1*Xdot, y*Ydot, LEFTOFF+x2*Xdot-1,
- (y+1)*Ydot-1, COLOR|OptionXor, OptionFill );
- }
-
- static void
- DrawRegion( x1, y1, x2, y2 )
- int x1,
- y1,
- x2,
- y2;
- {
- DrawBuf buf[90],
- *bufp= buf;
-
- if( y1 > y2 ){
- swap( y1, y2 );
- swap( x1, x2 );
- }
- if( y1 < y2 ){
- int len= strlen( CharBuf[y1] ),
- i;
- if( x1 < len + 1 )
- DrawSetRegion( bufp++, x1, len+1, y1 );
- for( i= y1+1 ; i < y2 ; i++ ){
- len = strlen( CharBuf[i] );
- DrawSetRegion( bufp++, 0, len+ 1, i );
- }
- if( 0 < x2 )
- DrawSetRegion( bufp++, 0, x2, y2 );
- }else{
- if( x1 > x2 )
- DrawSetRegion( bufp++, x2, x1, y1 );
- else if( x1 < x2 )
- DrawSetRegion( bufp++, x1, x2, y1 );
- else
- return;
- }
- WindowDraw( Cwp, buf, bufp-buf );
- }
-
- #if 0
- static int
- kpos( x, ptr )
- int x;
- unsigned char *ptr;
- {
- int kanji= FALSE;
- unsigned char *buf= ptr+x;
- for(; *ptr && ptr< buf ; ptr++ )
- kanji= ( !kanji && iskanji( *ptr ) );
- return kanji;
- }
- #endif
-
- /*
- WindowID wp; 描画するウィンドウの ID
- EventInfo *info;
- unsigned char **cb; スクリーンイメージを格納したポインタ
- int ScrV; 画面の縦方向の文字数
- int space_cut; 行末のスペースをカットする
- int font; フォントサイズ
- */
-
-
- asm( " .xdef _SetClipBoardOffset
- _SetClipBoardOffset equ _ClipSetOperation
- " );
-
- void
- ClipSetOperation( wp, info, cb, ScrV, xoff, yoff, space_cut, color, font )
- WindowID wp;
- EventInfo *info;
- unsigned char **cb;
- int ScrV,
- space_cut;
- unsigned int font;
- {
- int x1,
- y1,
- x2,
- y2;
-
- CharBuf= cb;
- Cwp= wp;
- Ydot= font;
- Xdot= font>>1;
- COLOR= color;
-
- if( info->x < xoff || info->y < yoff )
- return;
-
- info->x-= xoff;
- info->y-= yoff;
-
- /* set start position y */
- y2= y1= info->y/Ydot;
- if( y1 < 0 || ScrV <= y1 )
- return;
-
- /* set start position x */
- {
- int len= strlen( CharBuf[y1] );
- x1= (info->x /*-LEFTOFF*/)/Xdot;
- if( x1 > len+1 )
- x1= len+1;
- if( KanjiTestPosition( CharBuf[y1], x1 ) )
- x1--;
- x2= x1;
- }
-
- {
- int sx,
- sy,
- h,
- v,
- hx,
- hy;
- WindowGetScreenPosition( wp, &sx, &sy );
- WindowGetViewSize( wp, &h, &v );
- WindowGetHome( wp, &hx, &hy );
- sx += xoff /*LEFTOFF*/;
- h -= xoff /*LEFTOFF*/;
- sy += yoff;
- v -= yoff;
- while( info->LeftStat ){
- int x,
- y;
- WindowGetEventInfo( info );
- x= info->x -sx; /* set local position */
- y= info->y -sy;
- if( 0 <= x && x < h && 0 <= y && y < v ){
- int len;
- x= (x+hx)/Xdot;
- y= (y+hy)/Ydot;
- if( y >= ScrV )
- y= ScrV-1;
- len= strlen( CharBuf[y] );
- if( x < 0 )
- x= 0;
- if( x > len+1 )
- x= len+1;
- if( KanjiTestPosition( CharBuf[y], x ) )
- x--;
- if( y != y2 || x != x2 ){
- DrawRegion( x, y, x2, y2 );
- y2= y;
- x2= x;
- }
- }
- }
- }
- DrawRegion( x1, y1, x2, y2 );
-
- if( y1 > y2 ){
- swap( y1, y2 );
- swap( x1, x2 );
- }
-
- WindowResetCommon( "Clip Board" );
-
- {
- unsigned char *cp, *bp,
- **ptr= CharBuf+y1,
- *p;
- int len= 0,
- i;
- for( i= y1 ; i<= y2 ; i++ )
- len+= strlen( CharBuf[i] )+1;
- bp= cp= WindowGetCommon( "Clip Board", len );
- if( y1 < y2 ){
- unsigned char *b= cp;
- for( p= (*ptr++)+x1 ; *cp++= *p++ ;);
- if( space_cut ){
- for( cp-=2 ; cp > b && *cp == ' ' ; cp-- );
- cp+= 2;
- }
- cp[-1]= '\r';
- for( i= y2-y1-1 ; i-- ; cp[-1]= '\r' ){
- for( b= cp, p= *ptr++ ; *cp++= *p++ ;);
- if( space_cut ){
- for( cp-=2 ; cp > b && *cp == ' ' ; cp-- );
- cp+= 2;
- }
- }
- p= *ptr;
- i= x2;
- }else{
- i= x2-x1;
- p= *ptr +x1;
- if( x1 > x2 ){
- i= -i;
- p= *ptr +x2;
- }
- }
- for(; i-- ; *cp++= *p++ );
- *cp= '\0';
- if( cp > bp && !cp[-1] )
- cp[-1]= '\r';
- }
- }
-
-