Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Contents of /trunk/teraterm/teraterm/vtdisp.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3227 - (show annotations) (download) (as text)
Tue Mar 24 15:10:33 2009 UTC (15 years, 1 month ago) by maya
File MIME type: text/x-csrc
File size: 85901 byte(s)
CVS から SVN へ移行: 改行コードを LF から CR+LF へ変換
1 /* Tera Term
2 Copyright(C) 1994-1998 T. Teranishi
3 All rights reserved. */
4
5 /* TERATERM.EXE, VT terminal display routines */
6 #include "teraterm.h"
7 #include "tttypes.h"
8 #include "string.h"
9
10 #include "ttwinman.h"
11 #include "ttime.h"
12 #include "ttdialog.h"
13 #include "ttcommon.h"
14
15 #include "vtdisp.h"
16
17 #include <locale.h>
18
19 #define CurWidth 2
20
21 int WinWidth, WinHeight;
22 static BOOL Active = FALSE;
23 static BOOL CompletelyVisible;
24 HFONT VTFont[AttrFontMask+1];
25 int FontHeight, FontWidth, ScreenWidth, ScreenHeight;
26 BOOL AdjustSize;
27 BOOL DontChangeSize=FALSE;
28 #ifdef ALPHABLEND_TYPE2
29 static int CRTWidth, CRTHeight;
30 #endif
31 int CursorX, CursorY;
32 /* Virtual screen region */
33 RECT VirtualScreen;
34
35 // --- scrolling status flags
36 int WinOrgX, WinOrgY, NewOrgX, NewOrgY;
37
38 int NumOfLines, NumOfColumns;
39 int PageStart, BuffEnd;
40
41 static BOOL CursorOnDBCS = FALSE;
42 static LOGFONT VTlf;
43 static BOOL SaveWinSize = FALSE;
44 static int WinWidthOld, WinHeightOld;
45 static HBRUSH Background;
46 static COLORREF ANSIColor[256];
47 static int Dx[256];
48
49 // caret variables
50 static int CaretStatus;
51 static BOOL CaretEnabled = TRUE;
52
53 // ---- device context and status flags
54 static HDC VTDC = NULL; /* Device context for VT window */
55 static TCharAttr DCAttr;
56 static TCharAttr CurCharAttr;
57 static BOOL DCReverse;
58 static HFONT DCPrevFont;
59
60 TCharAttr DefCharAttr = {
61 AttrDefault,
62 AttrDefault,
63 AttrDefaultFG,
64 AttrDefaultBG
65 };
66
67 // scrolling
68 static int ScrollCount = 0;
69 static int dScroll = 0;
70 static int SRegionTop;
71 static int SRegionBottom;
72
73 #ifdef ALPHABLEND_TYPE2
74 //<!--by AKASI
75 #include "ttlib.h"
76 #include <stdio.h>
77 #include <time.h>
78
79 #define BG_SECTION "BG"
80
81 typedef enum _BG_TYPE {BG_COLOR = 0,BG_PICTURE,BG_WALLPAPER} BG_TYPE;
82 typedef enum _BG_PATTERN {BG_STRETCH = 0,BG_TILE,BG_CENTER,BG_FIT_WIDTH,BG_FIT_HEIGHT,BG_AUTOFIT} BG_PATTERN;
83
84 typedef struct _BGSrc
85 {
86 HDC hdc;
87 BG_TYPE type;
88 BG_PATTERN pattern;
89 BOOL antiAlias;
90 COLORREF color;
91 int alpha;
92 int width;
93 int height;
94 char file[MAX_PATH];
95 char fileTmp[MAX_PATH];
96 }BGSrc;
97
98 BGSrc BGDest;
99 BGSrc BGSrc1;
100 BGSrc BGSrc2;
101
102 int BGEnable;
103 int BGReverseTextAlpha;
104 int BGUseAlphaBlendAPI;
105 BOOL BGNoFrame;
106 BOOL BGFastSizeMove;
107
108 char BGSPIPath[MAX_PATH];
109
110 COLORREF BGVTColor[2];
111 COLORREF BGVTBoldColor[2];
112 COLORREF BGVTBlinkColor[2];
113 COLORREF BGVTReverseColor[2];
114 /* begin - ishizaki */
115 COLORREF BGURLColor[2];
116 /* end - ishizaki */
117
118 RECT BGPrevRect;
119 BOOL BGReverseText;
120
121 BOOL BGNoCopyBits;
122 BOOL BGInSizeMove;
123 HBRUSH BGBrushInSizeMove;
124
125 HDC hdcBGWork;
126 HDC hdcBGBuffer;
127 HDC hdcBG;
128
129 typedef struct tagWallpaperInfo
130 {
131 char filename[MAX_PATH];
132 int pattern;
133 }WallpaperInfo;
134
135 typedef struct _BGBLENDFUNCTION
136 {
137 BYTE BlendOp;
138 BYTE BlendFlags;
139 BYTE SourceConstantAlpha;
140 BYTE AlphaFormat;
141 }BGBLENDFUNCTION;
142
143 BOOL (FAR WINAPI *BGAlphaBlend)(HDC,int,int,int,int,HDC,int,int,int,int,BGBLENDFUNCTION);
144 BOOL (FAR WINAPI *BGEnumDisplayMonitors)(HDC,LPCRECT,MONITORENUMPROC,LPARAM);
145
146
147 //����������
148
149 void dprintf(char *format, ...)
150 {
151 va_list args;
152 char buffer[1024];
153
154 va_start(args,format);
155
156 _vsnprintf_s(buffer,sizeof(buffer),_TRUNCATE,format,args);
157 strncat_s(buffer,sizeof(buffer),"\n",_TRUNCATE);
158
159 OutputDebugString(buffer);
160 }
161
162 HBITMAP CreateScreenCompatibleBitmap(int width,int height)
163 {
164 HDC hdc;
165 HBITMAP hbm;
166
167 #ifdef _DEBUG
168 dprintf("CreateScreenCompatibleBitmap : width = %d height = %d",width,height);
169 #endif
170
171 hdc = GetDC(NULL);
172
173 hbm = CreateCompatibleBitmap(hdc,width,height);
174
175 ReleaseDC(NULL,hdc);
176
177 #ifdef _DEBUG
178 if(!hbm)
179 dprintf("CreateScreenCompatibleBitmap : fail in CreateCompatibleBitmap");
180 #endif
181
182 return hbm;
183 }
184
185 HBITMAP CreateDIB24BPP(int width,int height,unsigned char **buf,int *lenBuf)
186 {
187 HDC hdc;
188 HBITMAP hbm;
189 BITMAPINFO bmi;
190
191 #ifdef _DEBUG
192 dprintf("CreateDIB24BPP : width = %d height = %d",width,height);
193 #endif
194
195 if(!width || !height)
196 return NULL;
197
198 ZeroMemory(&bmi,sizeof(bmi));
199
200 *lenBuf = ((width * 3 + 3) & ~3) * height;
201
202 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
203 bmi.bmiHeader.biWidth = width;
204 bmi.bmiHeader.biHeight = height;
205 bmi.bmiHeader.biPlanes = 1;
206 bmi.bmiHeader.biBitCount = 24;
207 bmi.bmiHeader.biSizeImage = *lenBuf;
208 bmi.bmiHeader.biCompression = BI_RGB;
209
210 hdc = GetDC(NULL);
211
212 hbm = CreateDIBSection(hdc,&bmi,DIB_RGB_COLORS,(void**)buf,NULL,0);
213
214 ReleaseDC(NULL,hdc);
215
216 return hbm;
217 }
218
219 HDC CreateBitmapDC(HBITMAP hbm)
220 {
221 HDC hdc;
222
223 #ifdef _DEBUG
224 dprintf("CreateBitmapDC : hbm = %x",hbm);
225 #endif
226
227 hdc = CreateCompatibleDC(NULL);
228
229 SaveDC(hdc);
230 SelectObject(hdc,hbm);
231
232 return hdc;
233 }
234
235 void DeleteBitmapDC(HDC *hdc)
236 {
237 HBITMAP hbm;
238
239 #ifdef _DEBUG
240 dprintf("DeleteBitmapDC : *hdc = %x",hdc);
241 #endif
242
243 if(!hdc)
244 return;
245
246 if(!(*hdc))
247 return;
248
249 hbm = GetCurrentObject(*hdc,OBJ_BITMAP);
250
251 RestoreDC(*hdc,-1);
252 DeleteObject(hbm);
253 DeleteDC(*hdc);
254
255 *hdc = 0;
256 }
257
258 void FillBitmapDC(HDC hdc,COLORREF color)
259 {
260 HBITMAP hbm;
261 BITMAP bm;
262 RECT rect;
263 HBRUSH hBrush;
264
265 #ifdef _DEBUG
266 dprintf("FillBitmapDC : hdc = %x color = %x",hdc,color);
267 #endif
268
269 if(!hdc)
270 return;
271
272 hbm = GetCurrentObject(hdc,OBJ_BITMAP);
273 GetObject(hbm,sizeof(bm),&bm);
274
275 SetRect(&rect,0,0,bm.bmWidth,bm.bmHeight);
276 hBrush = CreateSolidBrush(color);
277 FillRect(hdc,&rect,hBrush);
278 DeleteObject(hBrush);
279 }
280
281 FARPROC GetProcAddressWithDllName(char *dllName,char *procName)
282 {
283 HINSTANCE hDll;
284
285 hDll = LoadLibrary(dllName);
286
287 if(hDll)
288 return GetProcAddress(hDll,procName);
289 else
290 return 0;
291 }
292
293 void RandomFile(char *filespec,char *filename, int destlen)
294 {
295 int i;
296 int file_num;
297 char fullpath[MAX_PATH];
298 char *filePart;
299
300 HANDLE hFind;
301 WIN32_FIND_DATA fd;
302
303 //�����p�X������
304 if(!GetFullPathName(filespec,MAX_PATH,fullpath,&filePart))
305 return;
306
307 //�t�@�C����������
308 hFind = FindFirstFile(fullpath,&fd);
309
310 file_num = 0;
311
312 if(hFind != INVALID_HANDLE_VALUE && filePart)
313 {
314
315 do{
316
317 if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
318 file_num ++;
319
320 }while(FindNextFile(hFind,&fd));
321
322 }
323
324 if(!file_num)
325 return;
326
327 FindClose(hFind);
328
329 //���������t�@�C�����������������B
330 file_num = rand()%file_num + 1;
331
332 hFind = FindFirstFile(fullpath,&fd);
333
334 if(hFind != INVALID_HANDLE_VALUE)
335 {
336 i = 0;
337
338 do{
339
340 if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
341 i ++;
342
343 }while(i < file_num && FindNextFile(hFind,&fd));
344
345 }else{
346 return;
347 }
348
349 FindClose(hFind);
350
351 //�f�B���N�g������
352 ZeroMemory(filename,destlen);
353 {
354 int tmplen;
355 char *tmp;
356 tmplen = filePart - fullpath + 1;
357 tmp = (char *)_alloca(tmplen);
358 strncpy_s(tmp,tmplen,fullpath,filePart - fullpath);
359 strncpy_s(filename,destlen,tmp,_TRUNCATE);
360 }
361 strncat_s(filename,destlen,fd.cFileName,_TRUNCATE);
362 }
363
364 BOOL LoadPictureWithSPI(char *nameSPI,char *nameFile,unsigned char *bufFile,long sizeFile,HLOCAL *hbuf,HLOCAL *hbmi)
365 {
366 HINSTANCE hSPI;
367 char spiVersion[8];
368 int (FAR PASCAL *SPI_IsSupported)(LPSTR,DWORD);
369 int (FAR PASCAL *SPI_GetPicture)(LPSTR,long,unsigned int,HANDLE *,HANDLE *,FARPROC,long);
370 int (FAR PASCAL *SPI_GetPluginInfo)(int,LPSTR,int);
371 int ret;
372
373 ret = FALSE;
374 hSPI = NULL;
375
376 //SPI �����[�h
377 hSPI = LoadLibrary(nameSPI);
378
379 if(!hSPI)
380 goto error;
381
382 (FARPROC)SPI_GetPluginInfo = GetProcAddress(hSPI,"GetPluginInfo");
383 (FARPROC)SPI_IsSupported = GetProcAddress(hSPI,"IsSupported");
384 (FARPROC)SPI_GetPicture = GetProcAddress(hSPI,"GetPicture");
385
386 if(!SPI_GetPluginInfo || !SPI_IsSupported || !SPI_GetPicture)
387 goto error;
388
389 //�o�[�W�����`�F�b�N
390 SPI_GetPluginInfo(0,spiVersion,8);
391
392 if(spiVersion[2] != 'I' || spiVersion[3] != 'N')
393 goto error;
394
395 if(!(SPI_IsSupported)(nameFile,(unsigned long)bufFile))
396 goto error;
397
398 if((SPI_GetPicture)(bufFile,sizeFile,1,hbmi,hbuf,NULL,0))
399 goto error;
400
401 ret = TRUE;
402
403 error :
404
405 if(hSPI)
406 FreeLibrary(hSPI);
407
408 return ret;
409 }
410
411 BOOL SaveBitmapFile(char *nameFile,unsigned char *pbuf,BITMAPINFO *pbmi)
412 {
413 int bmiSize;
414 DWORD writtenByte;
415 HANDLE hFile;
416 BITMAPFILEHEADER bfh;
417
418 hFile = CreateFile(nameFile,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
419
420 if(hFile == INVALID_HANDLE_VALUE)
421 return FALSE;
422
423 bmiSize = pbmi->bmiHeader.biSize;
424
425 switch(pbmi->bmiHeader.biBitCount)
426 {
427 case 1:
428 bmiSize += pbmi->bmiHeader.biClrUsed ? sizeof(RGBQUAD) * 2 : 0;
429 break;
430
431 case 2 :
432 bmiSize += sizeof(RGBQUAD) * 4;
433 break;
434
435 case 4 :
436 bmiSize += sizeof(RGBQUAD) * 16;
437 break;
438
439 case 8 :
440 bmiSize += sizeof(RGBQUAD) * 256;
441 break;
442 }
443
444 ZeroMemory(&bfh,sizeof(bfh));
445 bfh.bfType = MAKEWORD('B','M');
446 bfh.bfOffBits = sizeof(bfh) + bmiSize;
447 bfh.bfSize = bfh.bfOffBits + pbmi->bmiHeader.biSizeImage;
448
449 WriteFile(hFile,&bfh,sizeof(bfh) ,&writtenByte,0);
450 WriteFile(hFile,pbmi,bmiSize ,&writtenByte,0);
451 WriteFile(hFile,pbuf,pbmi->bmiHeader.biSizeImage,&writtenByte,0);
452
453 CloseHandle(hFile);
454
455 return TRUE;
456 }
457
458 BOOL FAR WINAPI AlphaBlendWithoutAPI(HDC hdcDest,int dx,int dy,int width,int height,HDC hdcSrc,int sx,int sy,int sw,int sh,BGBLENDFUNCTION bf)
459 {
460 HDC hdcDestWork,hdcSrcWork;
461 int i,invAlpha,alpha;
462 int lenBuf;
463 unsigned char *bufDest;
464 unsigned char *bufSrc;
465
466 if(dx != 0 || dy != 0 || sx != 0 || sy != 0 || width != sw || height != sh)
467 return FALSE;
468
469 hdcDestWork = CreateBitmapDC(CreateDIB24BPP(width,height,&bufDest,&lenBuf));
470 hdcSrcWork = CreateBitmapDC(CreateDIB24BPP(width,height,&bufSrc ,&lenBuf));
471
472 if(!bufDest || !bufSrc)
473 return FALSE;
474
475 BitBlt(hdcDestWork,0,0,width,height,hdcDest,0,0,SRCCOPY);
476 BitBlt(hdcSrcWork ,0,0,width,height,hdcSrc ,0,0,SRCCOPY);
477
478 alpha = bf.SourceConstantAlpha;
479 invAlpha = 255 - alpha;
480
481 for(i = 0;i < lenBuf;i++,bufDest++,bufSrc++)
482 *bufDest = (*bufDest * invAlpha + *bufSrc * alpha)>>8;
483
484 BitBlt(hdcDest,0,0,width,height,hdcDestWork,0,0,SRCCOPY);
485
486 DeleteBitmapDC(&hdcDestWork);
487 DeleteBitmapDC(&hdcSrcWork);
488
489 return TRUE;
490 }
491
492 // ���������������W
493
494 void BGPreloadPicture(BGSrc *src)
495 {
496 char spiPath[MAX_PATH];
497 char filespec[MAX_PATH];
498 char *filePart;
499 int fileSize;
500 int readByte;
501 unsigned char *fileBuf;
502
503 HBITMAP hbm;
504 HANDLE hPictureFile;
505 HANDLE hFind;
506 WIN32_FIND_DATA fd;
507
508 #ifdef _DEBUG
509 dprintf("Preload Picture : %s",src->file);
510 #endif
511
512 //�t�@�C������������
513 hPictureFile = CreateFile(src->file,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
514
515 if(hPictureFile == INVALID_HANDLE_VALUE)
516 return;
517
518 fileSize = GetFileSize(hPictureFile,0);
519
520 //���� 2kb ���m�� (Susie plugin ���d�l����)
521 fileBuf = GlobalAlloc(GPTR,fileSize + 2048);
522
523 //���� 2kb ���O��������
524 ZeroMemory(fileBuf,2048);
525
526 ReadFile(hPictureFile,fileBuf,fileSize,&readByte,0);
527
528 CloseHandle(hPictureFile);
529
530 // SPIPath �������p�X������
531 if(!GetFullPathName(BGSPIPath,MAX_PATH,filespec,&filePart))
532 return;
533
534 //�v���O�C����������������
535 hFind = FindFirstFile(filespec,&fd);
536
537 if(hFind != INVALID_HANDLE_VALUE && filePart)
538 {
539 //�f�B���N�g������
540 ExtractDirName(filespec, spiPath);
541 AppendSlash(spiPath, sizeof(spiPath));
542
543 do{
544 HLOCAL hbuf,hbmi;
545 BITMAPINFO *pbmi;
546 char *pbuf;
547 char spiFileName[MAX_PATH];
548
549 if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
550 continue;
551
552 strncpy_s(spiFileName, sizeof(spiFileName), spiPath, _TRUNCATE);
553 strncat_s(spiFileName, sizeof(spiFileName), fd.cFileName, _TRUNCATE);
554
555 if(LoadPictureWithSPI(spiFileName,src->file,fileBuf,fileSize,&hbuf,&hbmi))
556 {
557 pbuf = LocalLock(hbuf);
558 pbmi = LocalLock(hbmi);
559
560 SaveBitmapFile(src->fileTmp,pbuf,pbmi);
561
562 LocalUnlock(hbmi);
563 LocalUnlock(hbuf);
564
565 LocalFree(hbmi);
566 LocalFree(hbuf);
567
568 strncpy_s(src->file, sizeof(src->file),src->fileTmp, _TRUNCATE);
569
570 break;
571 }
572 }while(FindNextFile(hFind,&fd));
573
574 FindClose(hFind);
575 }
576
577 GlobalFree(fileBuf);
578
579 //�������r�b�g�}�b�v��������������
580
581 hbm = LoadImage(0,src->file,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
582
583 if(hbm)
584 {
585 BITMAP bm;
586
587 GetObject(hbm,sizeof(bm),&bm);
588
589 src->hdc = CreateBitmapDC(hbm);
590 src->width = bm.bmWidth;
591 src->height = bm.bmHeight;
592 }else{
593 src->type = BG_COLOR;
594 }
595 }
596
597 void BGGetWallpaperInfo(WallpaperInfo *wi)
598 {
599 int length;
600 int tile;
601 char str[256];
602 HKEY hKey;
603
604 wi->pattern = BG_CENTER;
605 strncpy_s(wi->filename, sizeof(wi->filename),"", _TRUNCATE);
606
607 //���W�X�g���L�[���I�[�v��
608 if(RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
609 return;
610
611 //�������Q�b�g
612 length = MAX_PATH;
613 RegQueryValueEx(hKey,"Wallpaper" ,NULL,NULL,(BYTE*)(wi->filename),&length);
614
615 //�����X�^�C���Q�b�g
616 length = 256;
617 RegQueryValueEx(hKey,"WallpaperStyle",NULL,NULL,(BYTE*)str,&length);
618 wi->pattern = atoi(str);
619
620 //�����X�^�C���Q�b�g
621 length = 256;
622 RegQueryValueEx(hKey,"TileWallpaper" ,NULL,NULL,(BYTE*)str,&length);
623 tile = atoi(str);
624
625 //�������������H
626 if(tile)
627 wi->pattern = BG_TILE;
628 else
629 if(wi->pattern == 0)
630 wi->pattern = BG_CENTER;
631 else
632 if(wi->pattern == 2)
633 wi->pattern = BG_STRETCH;
634
635 //���W�X�g���L�[���N���[�Y
636 RegCloseKey(hKey);
637 }
638
639 void BGPreloadWallpaper(BGSrc *src)
640 {
641 HBITMAP hbm;
642 WallpaperInfo wi;
643
644 BGGetWallpaperInfo(&wi);
645
646 //��������������
647 //LR_CREATEDIBSECTION ���w�����������R�c
648 if(wi.pattern == BG_STRETCH)
649 hbm = LoadImage(0,wi.filename,IMAGE_BITMAP,CRTWidth,CRTHeight,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
650 else
651 hbm = LoadImage(0,wi.filename,IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE);
652
653 //����DC������
654 if(hbm)
655 {
656 BITMAP bm;
657
658 GetObject(hbm,sizeof(bm),&bm);
659
660 src->hdc = CreateBitmapDC(hbm);
661 src->width = bm.bmWidth;
662 src->height = bm.bmHeight;
663 src->pattern = wi.pattern;
664 }else{
665 src->hdc = NULL;
666 }
667
668 src->color = GetSysColor(COLOR_DESKTOP);
669 }
670
671 void BGPreloadSrc(BGSrc *src)
672 {
673 DeleteBitmapDC(&(src->hdc));
674
675 switch(src->type)
676 {
677 case BG_COLOR :
678 break;
679
680 case BG_WALLPAPER :
681 BGPreloadWallpaper(src);
682 break;
683
684 case BG_PICTURE :
685 BGPreloadPicture(src);
686 break;
687 }
688 }
689
690 void BGStretchPicture(HDC hdcDest,BGSrc *src,int x,int y,int width,int height,BOOL bAntiAlias)
691 {
692 if(!hdcDest || !src)
693 return;
694
695 if(bAntiAlias)
696 {
697 if(src->width != width || src->height != height)
698 {
699 HBITMAP hbm;
700
701 hbm = LoadImage(0,src->file,IMAGE_BITMAP,width,height,LR_LOADFROMFILE);
702
703 if(!hbm)
704 return;
705
706 DeleteBitmapDC(&(src->hdc));
707 src->hdc = CreateBitmapDC(hbm);
708 src->width = width;
709 src->height = height;
710 }
711
712 BitBlt(hdcDest,x,y,width,height,src->hdc,0,0,SRCCOPY);
713 }else{
714 SetStretchBltMode(src->hdc,COLORONCOLOR);
715 StretchBlt(hdcDest,x,y,width,height,src->hdc,0,0,src->width,src->height,SRCCOPY);
716 }
717 }
718
719 void BGLoadPicture(HDC hdcDest,BGSrc *src)
720 {
721 int x,y,width,height,pattern;
722 HDC hdc = NULL;
723
724 FillBitmapDC(hdcDest,src->color);
725
726 if(!src->height || !src->width)
727 return;
728
729 if(src->pattern == BG_AUTOFIT){
730 if((src->height * ScreenWidth) > (ScreenHeight * src->width))
731 pattern = BG_FIT_WIDTH;
732 else
733 pattern = BG_FIT_HEIGHT;
734 }else{
735 pattern = src->pattern;
736 }
737
738 switch(pattern)
739 {
740 case BG_STRETCH :
741 BGStretchPicture(hdcDest,src,0,0,ScreenWidth,ScreenHeight,src->antiAlias);
742 break;
743
744 case BG_FIT_WIDTH :
745
746 height = (src->height * ScreenWidth) / src->width;
747 y = (ScreenHeight - height) / 2;
748
749 BGStretchPicture(hdcDest,src,0,y,ScreenWidth,height,src->antiAlias);
750 break;
751
752 case BG_FIT_HEIGHT :
753
754 width = (src->width * ScreenHeight) / src->height;
755 x = (ScreenWidth - width) / 2;
756
757 BGStretchPicture(hdcDest,src,x,0,width,ScreenHeight,src->antiAlias);
758 break;
759
760 case BG_TILE :
761 for(x = 0;x < ScreenWidth ;x += src->width )
762 for(y = 0;y < ScreenHeight;y += src->height)
763 BitBlt(hdcDest,x,y,src->width,src->height,src->hdc,0,0,SRCCOPY);
764 break;
765
766 case BG_CENTER :
767 x = (ScreenWidth - src->width) / 2;
768 y = (ScreenHeight - src->height) / 2;
769
770 BitBlt(hdcDest,x,y,src->width,src->height,src->hdc,0,0,SRCCOPY);
771 break;
772 }
773 }
774
775 typedef struct tagLoadWallpaperStruct
776 {
777 RECT *rectClient;
778 HDC hdcDest;
779 BGSrc *src;
780 }LoadWallpaperStruct;
781
782 BOOL CALLBACK BGLoadWallpaperEnumFunc(HMONITOR hMonitor,HDC hdcMonitor,LPRECT lprcMonitor,LPARAM dwData)
783 {
784 RECT rectDest;
785 RECT rectRgn;
786 int monitorWidth;
787 int monitorHeight;
788 int destWidth;
789 int destHeight;
790 HRGN hRgn;
791 int x;
792 int y;
793
794 LoadWallpaperStruct *lws = (LoadWallpaperStruct*)dwData;
795
796 if(!IntersectRect(&rectDest,lprcMonitor,lws->rectClient))
797 return TRUE;
798
799 //���j�^�[�������������������}�X�N
800 SaveDC(lws->hdcDest);
801 CopyRect(&rectRgn,&rectDest);
802 OffsetRect(&rectRgn,- lws->rectClient->left,- lws->rectClient->top);
803 hRgn = CreateRectRgnIndirect(&rectRgn);
804 SelectObject(lws->hdcDest,hRgn);
805
806 //���j�^�[��������
807 monitorWidth = lprcMonitor->right - lprcMonitor->left;
808 monitorHeight = lprcMonitor->bottom - lprcMonitor->top;
809
810 destWidth = rectDest.right - rectDest.left;
811 destHeight = rectDest.bottom - rectDest.top;
812
813 switch(lws->src->pattern)
814 {
815 case BG_CENTER :
816 case BG_STRETCH :
817
818 SetWindowOrgEx(lws->src->hdc,
819 lprcMonitor->left + (monitorWidth - lws->src->width )/2,
820 lprcMonitor->top + (monitorHeight - lws->src->height)/2,NULL);
821 BitBlt(lws->hdcDest ,rectDest.left,rectDest.top,destWidth,destHeight,
822 lws->src->hdc,rectDest.left,rectDest.top,SRCCOPY);
823
824 break;
825 case BG_TILE :
826
827 SetWindowOrgEx(lws->src->hdc,0,0,NULL);
828
829 for(x = rectDest.left - (rectDest.left % lws->src->width ) - lws->src->width ;
830 x < rectDest.right ;x += lws->src->width )
831 for(y = rectDest.top - (rectDest.top % lws->src->height) - lws->src->height;
832 y < rectDest.bottom;y += lws->src->height)
833 BitBlt(lws->hdcDest,x,y,lws->src->width,lws->src->height,lws->src->hdc,0,0,SRCCOPY);
834 break;
835 }
836
837 //���[�W�������j��
838 RestoreDC(lws->hdcDest,-1);
839 DeleteObject(hRgn);
840
841 return TRUE;
842 }
843
844 void BGLoadWallpaper(HDC hdcDest,BGSrc *src)
845 {
846 RECT rectClient;
847 POINT point;
848 LoadWallpaperStruct lws;
849
850 //�����������f�X�N�g�b�v�F���h��������
851 FillBitmapDC(hdcDest,src->color);
852
853 //����������������������
854 if(!src->hdc)
855 return;
856
857 //hdcDest�����W�n�����z�X�N���[������������
858 point.x = 0;
859 point.y = 0;
860 ClientToScreen(HVTWin,&point);
861
862 SetWindowOrgEx(hdcDest,point.x,point.y,NULL);
863
864 //���z�X�N���[�������N���C�A���g����
865 GetClientRect(HVTWin,&rectClient);
866 OffsetRect(&rectClient,point.x,point.y);
867
868 //���j�^�[������
869 lws.rectClient = &rectClient;
870 lws.src = src;
871 lws.hdcDest = hdcDest;
872
873 if(BGEnumDisplayMonitors)
874 {
875 (*BGEnumDisplayMonitors)(NULL,NULL,BGLoadWallpaperEnumFunc,(LPARAM)&lws);
876 }else{
877 RECT rectMonitor;
878
879 SetRect(&rectMonitor,0,0,CRTWidth,CRTHeight);
880 BGLoadWallpaperEnumFunc(NULL,NULL,&rectMonitor,(LPARAM)&lws);
881 }
882
883 //���W�n������
884 SetWindowOrgEx(hdcDest,0,0,NULL);
885 }
886
887 void BGLoadSrc(HDC hdcDest,BGSrc *src)
888 {
889 switch(src->type)
890 {
891 case BG_COLOR :
892 FillBitmapDC(hdcDest,src->color);
893 break;
894
895 case BG_WALLPAPER :
896 BGLoadWallpaper(hdcDest,src);
897 break;
898
899 case BG_PICTURE :
900 BGLoadPicture(hdcDest,src);
901 break;
902 }
903 }
904
905 void BGSetupPrimary(BOOL forceSetup)
906 {
907 POINT point;
908 RECT rect;
909
910 if(!BGEnable)
911 return;
912
913 //�������u�A�������������������`�F�b�N
914 point.x = 0;
915 point.y = 0;
916 ClientToScreen(HVTWin,&point);
917
918 GetClientRect(HVTWin,&rect);
919 OffsetRect(&rect,point.x,point.y);
920
921 if(!forceSetup && EqualRect(&rect,&BGPrevRect))
922 return;
923
924 CopyRect(&BGPrevRect,&rect);
925
926 #ifdef _DEBUG
927 dprintf("BGSetupPrimary : BGInSizeMove = %d",BGInSizeMove);
928 #endif
929
930 //�����p DC ����
931 if(hdcBGWork) DeleteBitmapDC(&hdcBGWork);
932 if(hdcBGBuffer) DeleteBitmapDC(&hdcBGBuffer);
933
934 hdcBGWork = CreateBitmapDC(CreateScreenCompatibleBitmap(ScreenWidth,FontHeight));
935 hdcBGBuffer = CreateBitmapDC(CreateScreenCompatibleBitmap(ScreenWidth,FontHeight));
936
937 //hdcBGBuffer ����������
938 SetBkMode(hdcBGBuffer,TRANSPARENT);
939
940 if(!BGInSizeMove)
941 {
942 BGBLENDFUNCTION bf;
943 HDC hdcSrc = NULL;
944
945 //�w�i HDC
946 if(hdcBG) DeleteBitmapDC(&hdcBG);
947 hdcBG = CreateBitmapDC(CreateScreenCompatibleBitmap(ScreenWidth,ScreenHeight));
948
949 //�����pDC
950 hdcSrc = CreateBitmapDC(CreateScreenCompatibleBitmap(ScreenWidth,ScreenHeight));
951
952 //�w�i����
953 BGLoadSrc(hdcBG,&BGDest);
954
955 ZeroMemory(&bf,sizeof(bf));
956 bf.BlendOp = AC_SRC_OVER;
957
958 if(bf.SourceConstantAlpha = BGSrc1.alpha)
959 {
960 BGLoadSrc(hdcSrc,&BGSrc1);
961 (BGAlphaBlend)(hdcBG,0,0,ScreenWidth,ScreenHeight,hdcSrc,0,0,ScreenWidth,ScreenHeight,bf);
962 }
963
964 if(bf.SourceConstantAlpha = BGSrc2.alpha)
965 {
966 BGLoadSrc(hdcSrc,&BGSrc2);
967 (BGAlphaBlend)(hdcBG,0,0,ScreenWidth,ScreenHeight,hdcSrc,0,0,ScreenWidth,ScreenHeight,bf);
968 }
969
970 DeleteBitmapDC(&hdcSrc);
971 }
972 }
973
974 COLORREF BGGetColor(char *name,COLORREF defcolor,char *file)
975 {
976 unsigned int r,g,b;
977 char colorstr[256],defstr[256];
978
979 _snprintf_s(defstr,sizeof(defstr),_TRUNCATE,"%d,%d,%d",GetRValue(defcolor),GetGValue(defcolor),GetBValue(defcolor));
980
981 GetPrivateProfileString(BG_SECTION,name,defstr,colorstr,255,file);
982
983 r = g = b = 0;
984
985 sscanf(colorstr,"%d , %d , %d",&r,&g,&b);
986
987 return RGB(r,g,b);
988 }
989
990 BG_PATTERN BGGetStrIndex(char *name,BG_PATTERN def,char *file,char **strList,int nList)
991 {
992 char defstr[64],str[64];
993 int i;
994
995 def %= nList;
996
997 strncpy_s(defstr, sizeof(defstr),strList[def], _TRUNCATE);
998 GetPrivateProfileString(BG_SECTION,name,defstr,str,64,file);
999
1000 for(i = 0;i < nList;i++)
1001 if(!_stricmp(str,strList[i]))
1002 return i;
1003
1004 return 0;
1005 }
1006
1007 BOOL BGGetOnOff(char *name,BOOL def,char *file)
1008 {
1009 char *strList[2] = {"Off","On"};
1010
1011 return BGGetStrIndex(name,def,file,strList,2);
1012 }
1013
1014 BG_PATTERN BGGetPattern(char *name,BG_PATTERN def,char *file)
1015 {
1016 char *strList[6]={"stretch","tile","center","fitwidth","fitheight","autofit"};
1017
1018 return BGGetStrIndex(name,def,file,strList,6);
1019 }
1020
1021 BG_PATTERN BGGetType(char *name,BG_TYPE def,char *file)
1022 {
1023 char *strList[3]={"color","picture","wallpaper"};
1024
1025 return BGGetStrIndex(name,def,file,strList,3);
1026 }
1027
1028 void BGReadTextColorConfig(char *file)
1029 {
1030 ANSIColor[IdFore ] = BGGetColor("Fore" ,ANSIColor[IdFore],file);
1031 ANSIColor[IdBack ] = BGGetColor("Back" ,ANSIColor[IdBack],file);
1032 ANSIColor[IdRed ] = BGGetColor("Red" ,ANSIColor[IdRed ],file);
1033 ANSIColor[IdGreen ] = BGGetColor("Green" ,ANSIColor[IdGreen ],file);
1034 ANSIColor[IdYellow ] = BGGetColor("Yellow" ,ANSIColor[IdYellow ],file);
1035 ANSIColor[IdBlue ] = BGGetColor("Blue" ,ANSIColor[IdBlue ],file);
1036 ANSIColor[IdMagenta] = BGGetColor("Magenta",ANSIColor[IdMagenta],file);
1037 ANSIColor[IdCyan ] = BGGetColor("Cyan" ,ANSIColor[IdCyan ],file);
1038
1039 ANSIColor[IdFore + 8] = BGGetColor("DarkFore" ,ANSIColor[IdFore + 8],file);
1040 ANSIColor[IdBack + 8] = BGGetColor("DarkBack" ,ANSIColor[IdBack + 8],file);
1041 ANSIColor[IdRed + 8] = BGGetColor("DarkRed" ,ANSIColor[IdRed + 8],file);
1042 ANSIColor[IdGreen + 8] = BGGetColor("DarkGreen" ,ANSIColor[IdGreen + 8],file);
1043 ANSIColor[IdYellow + 8] = BGGetColor("DarkYellow" ,ANSIColor[IdYellow + 8],file);
1044 ANSIColor[IdBlue + 8] = BGGetColor("DarkBlue" ,ANSIColor[IdBlue + 8],file);
1045 ANSIColor[IdMagenta+ 8] = BGGetColor("DarkMagenta",ANSIColor[IdMagenta+ 8],file);
1046 ANSIColor[IdCyan + 8] = BGGetColor("DarkCyan" ,ANSIColor[IdCyan + 8],file);
1047
1048 BGVTColor[0] = BGGetColor("VTFore",BGVTColor[0],file);
1049 BGVTColor[1] = BGGetColor("VTBack",BGVTColor[1],file);
1050
1051 BGVTBlinkColor[0] = BGGetColor("VTBlinkFore",BGVTBlinkColor[0],file);
1052 BGVTBlinkColor[1] = BGGetColor("VTBlinkBack",BGVTBlinkColor[1],file);
1053
1054 BGVTBoldColor[0] = BGGetColor("VTBoldFore" ,BGVTBoldColor[0],file);
1055 BGVTBoldColor[1] = BGGetColor("VTBoldBack" ,BGVTBoldColor[1],file);
1056
1057 BGVTReverseColor[0] = BGGetColor("VTReverseFore" ,BGVTReverseColor[0],file);
1058 BGVTReverseColor[1] = BGGetColor("VTReverseBack" ,BGVTReverseColor[1],file);
1059
1060 /* begin - ishizaki */
1061 BGURLColor[0] = BGGetColor("URLFore" ,BGURLColor[0],file);
1062 BGURLColor[1] = BGGetColor("URLBack" ,BGURLColor[1],file);
1063 /* end - ishizaki */
1064 }
1065
1066 void BGReadIniFile(char *file)
1067 {
1068 char path[MAX_PATH];
1069
1070 // Easy Setting
1071 BGDest.pattern = BGGetPattern("BGPicturePattern",BGSrc1.pattern,file);
1072 BGDest.color = BGGetColor("BGPictureBaseColor",BGSrc1.color,file);
1073
1074 GetPrivateProfileString(BG_SECTION,"BGPictureFile",BGSrc1.file,path,MAX_PATH,file);
1075 RandomFile(path,BGDest.file,sizeof(BGDest.file));
1076
1077 BGSrc1.alpha = 255 - GetPrivateProfileInt(BG_SECTION,"BGPictureTone",255 - BGSrc1.alpha,file);
1078
1079 if(!strcmp(BGDest.file,""))
1080 BGSrc1.alpha = 255;
1081
1082 BGSrc2.alpha = 255 - GetPrivateProfileInt(BG_SECTION,"BGFadeTone",255 - BGSrc2.alpha,file);
1083 BGSrc2.color = BGGetColor("BGFadeColor",BGSrc2.color,file);
1084
1085 BGReverseTextAlpha = GetPrivateProfileInt(BG_SECTION,"BGReverseTextTone",BGReverseTextAlpha,file);
1086
1087 //Src1 �������o��
1088 BGSrc1.type = BGGetType("BGSrc1Type",BGSrc1.type,file);
1089 BGSrc1.pattern = BGGetPattern("BGSrc1Pattern",BGSrc1.pattern,file);
1090 BGSrc1.antiAlias = BGGetOnOff("BGSrc1AntiAlias",BGSrc1.antiAlias,file);
1091 BGSrc1.alpha = GetPrivateProfileInt(BG_SECTION,"BGSrc1Alpha" ,BGSrc1.alpha ,file);
1092 BGSrc1.color = BGGetColor("BGSrc1Color",BGSrc1.color,file);
1093
1094 GetPrivateProfileString(BG_SECTION,"BGSrc1File",BGSrc1.file,path,MAX_PATH,file);
1095 RandomFile(path,BGSrc1.file,sizeof(BGSrc1.file));
1096
1097 //Src2 �������o��
1098 BGSrc2.type = BGGetType("BGSrc2Type",BGSrc2.type,file);
1099 BGSrc2.pattern = BGGetPattern("BGSrc2Pattern",BGSrc2.pattern,file);
1100 BGSrc2.antiAlias = BGGetOnOff("BGSrc2AntiAlias",BGSrc2.antiAlias,file);
1101 BGSrc2.alpha = GetPrivateProfileInt(BG_SECTION,"BGSrc2Alpha" ,BGSrc2.alpha ,file);
1102 BGSrc2.color = BGGetColor("BGSrc2Color",BGSrc2.color,file);
1103
1104 GetPrivateProfileString(BG_SECTION,"BGSrc2File",BGSrc2.file,path,MAX_PATH,file);
1105 RandomFile(path,BGSrc2.file,sizeof(BGSrc2.file));
1106
1107 //Dest �������o��
1108 BGDest.type = BGGetType("BGDestType",BGDest.type,file);
1109 BGDest.pattern = BGGetPattern("BGDestPattern",BGDest.pattern,file);
1110 BGDest.antiAlias = BGGetOnOff("BGDestAntiAlias",BGDest.antiAlias,file);
1111 BGDest.color = BGGetColor("BGDestColor",BGDest.color,file);
1112
1113 GetPrivateProfileString(BG_SECTION,"BGDestFile",BGDest.file,path,MAX_PATH,file);
1114 RandomFile(path,BGDest.file,sizeof(BGDest.file));
1115
1116 //�����������o��
1117 BGReverseTextAlpha = GetPrivateProfileInt(BG_SECTION,"BGReverseTextAlpha",BGReverseTextAlpha,file);
1118 BGReadTextColorConfig(file);
1119 }
1120
1121 void BGDestruct(void)
1122 {
1123 if(!BGEnable)
1124 return;
1125
1126 DeleteBitmapDC(&hdcBGBuffer);
1127 DeleteBitmapDC(&hdcBGWork);
1128 DeleteBitmapDC(&hdcBG);
1129 DeleteBitmapDC(&(BGDest.hdc));
1130 DeleteBitmapDC(&(BGSrc1.hdc));
1131 DeleteBitmapDC(&(BGSrc2.hdc));
1132
1133 //�e���|�����[�t�@�C������
1134 DeleteFile(BGDest.fileTmp);
1135 DeleteFile(BGSrc1.fileTmp);
1136 DeleteFile(BGSrc2.fileTmp);
1137 }
1138
1139 void BGInitialize(void)
1140 {
1141 char path[MAX_PATH],config_file[MAX_PATH],tempPath[MAX_PATH];
1142
1143 // VTColor ����������
1144 BGVTColor[0] = ts.VTColor[0];
1145 BGVTColor[1] = ts.VTColor[1];
1146
1147 BGVTBoldColor[0] = ts.VTBoldColor[0];
1148 BGVTBoldColor[1] = ts.VTBoldColor[1];
1149
1150 BGVTBlinkColor[0] = ts.VTBlinkColor[0];
1151 BGVTBlinkColor[1] = ts.VTBlinkColor[1];
1152
1153 BGVTReverseColor[0] = ts.VTReverseColor[0];
1154 BGVTReverseColor[1] = ts.VTReverseColor[1];
1155
1156 #if 0
1157 /* begin - ishizaki */
1158 BGURLColor[0] = ts.URLColor[0];
1159 BGURLColor[1] = ts.URLColor[1];
1160 /* end - ishizaki */
1161 #else
1162 // TODO: �n�C�p�[�����N���`�������A���^�C�����s�����������������������A
1163 // �F�������X�������������������������������B�����A���������B(2005.4.3 yutaka)
1164 BGURLColor[0] = ts.VTColor[0];
1165 BGURLColor[1] = ts.VTColor[1];
1166 #endif
1167
1168 // ANSI color�������������D�������� (2005.2.3 yutaka)
1169 InitColorTable();
1170
1171 //���\�[�X����
1172 BGDestruct();
1173
1174 //BG ���L�����`�F�b�N
1175 ts.EtermLookfeel.BGEnable = BGEnable = BGGetOnOff("BGEnable",FALSE,ts.SetupFName);
1176 ts.EtermLookfeel.BGUseAlphaBlendAPI = BGGetOnOff("BGUseAlphaBlendAPI",TRUE ,ts.SetupFName);
1177 ts.EtermLookfeel.BGNoFrame = BGGetOnOff("BGNoFrame" ,FALSE,ts.SetupFName);
1178 ts.EtermLookfeel.BGFastSizeMove = BGGetOnOff("BGFastSizeMove" ,TRUE ,ts.SetupFName);
1179 ts.EtermLookfeel.BGNoCopyBits = BGGetOnOff("BGFlickerlessMove" ,TRUE ,ts.SetupFName);
1180
1181 GetPrivateProfileString(BG_SECTION,"BGSPIPath","plugin",BGSPIPath,MAX_PATH,ts.SetupFName);
1182 strncpy_s(ts.EtermLookfeel.BGSPIPath, sizeof(ts.EtermLookfeel.BGSPIPath), BGSPIPath, _TRUNCATE);
1183
1184 //�R���t�B�O�t�@�C��������
1185 GetPrivateProfileString(BG_SECTION,"BGThemeFile","",path,MAX_PATH,ts.SetupFName);
1186 strncpy_s(ts.EtermLookfeel.BGThemeFile, sizeof(ts.EtermLookfeel.BGThemeFile), path, _TRUNCATE);
1187
1188 if(!BGEnable)
1189 return;
1190
1191 //����������
1192 // add cast (2006.2.18 yutaka)
1193 srand((unsigned int)time(NULL));
1194
1195 //BG�V�X�e�����������o��
1196 BGUseAlphaBlendAPI = ts.EtermLookfeel.BGUseAlphaBlendAPI;
1197 BGNoFrame = ts.EtermLookfeel.BGNoFrame;
1198 BGFastSizeMove = ts.EtermLookfeel.BGFastSizeMove;
1199 BGNoCopyBits = ts.EtermLookfeel.BGNoCopyBits;
1200
1201 #if 0
1202 GetPrivateProfileString(BG_SECTION,"BGSPIPath","plugin",BGSPIPath,MAX_PATH,ts.SetupFName);
1203 strncpy_s(ts.EtermLookfeel.BGSPIPath, sizeof(ts.EtermLookfeel.BGSPIPath), BGSPIPath, _TRUNCATE);
1204 #endif
1205
1206 //�e���|�����[�t�@�C����������
1207 GetTempPath(MAX_PATH,tempPath);
1208 GetTempFileName(tempPath,"ttAK",0,BGDest.fileTmp);
1209 GetTempFileName(tempPath,"ttAK",0,BGSrc1.fileTmp);
1210 GetTempFileName(tempPath,"ttAK",0,BGSrc2.fileTmp);
1211
1212 //�f�t�H���g�l
1213 BGDest.type = BG_PICTURE;
1214 BGDest.pattern = BG_STRETCH;
1215 BGDest.color = RGB(0,0,0);
1216 BGDest.antiAlias = TRUE;
1217 strncpy_s(BGDest.file, sizeof(BGDest.file),"", _TRUNCATE);
1218
1219 BGSrc1.type = BG_WALLPAPER;
1220 BGSrc1.pattern = BG_STRETCH;
1221 BGSrc1.color = RGB(255,255,255);
1222 BGSrc1.antiAlias = TRUE;
1223 BGSrc1.alpha = 255;
1224 strncpy_s(BGSrc1.file, sizeof(BGSrc1.file),"", _TRUNCATE);
1225
1226 BGSrc2.type = BG_COLOR;
1227 BGSrc2.pattern = BG_STRETCH;
1228 BGSrc2.color = RGB(0,0,0);
1229 BGSrc2.antiAlias = TRUE;
1230 BGSrc2.alpha = 128;
1231 strncpy_s(BGSrc2.file, sizeof(BGSrc2.file),"", _TRUNCATE);
1232
1233 BGReverseTextAlpha = 255;
1234
1235 //�����������o��
1236 BGReadIniFile(ts.SetupFName);
1237
1238 //�R���t�B�O�t�@�C��������
1239 GetPrivateProfileString(BG_SECTION,"BGThemeFile","",path,MAX_PATH,ts.SetupFName);
1240 RandomFile(path,config_file,sizeof(config_file));
1241
1242 //�������I�[�o�[���C�h
1243 if(strcmp(config_file,""))
1244 {
1245 char dir[MAX_PATH],prevDir[MAX_PATH];
1246
1247 //INI�t�@�C���������f�B���N�g���������I������
1248 GetCurrentDirectory(MAX_PATH,prevDir);
1249
1250 ExtractDirName(config_file,dir);
1251 SetCurrentDirectory(dir);
1252
1253 BGReadIniFile(config_file);
1254
1255 SetCurrentDirectory(prevDir);
1256 }
1257
1258 //SPI ���p�X�����`
1259 AppendSlash(BGSPIPath,sizeof(BGSPIPath));
1260 strncat_s(BGSPIPath,sizeof(BGSPIPath),"*",_TRUNCATE);
1261
1262 //���� or �w�i���v�����[�h
1263 BGPreloadSrc(&BGDest);
1264 BGPreloadSrc(&BGSrc1);
1265 BGPreloadSrc(&BGSrc2);
1266
1267 // AlphaBlend ���A�h���X����������
1268 if(BGUseAlphaBlendAPI)
1269 (FARPROC)BGAlphaBlend = GetProcAddressWithDllName("msimg32.dll","AlphaBlend");
1270 else
1271 BGAlphaBlend = NULL;
1272
1273 if(!BGAlphaBlend)
1274 BGAlphaBlend = AlphaBlendWithoutAPI;
1275
1276 //EnumDisplayMonitors ���T��
1277 (FARPROC)BGEnumDisplayMonitors = GetProcAddressWithDllName("user32.dll","EnumDisplayMonitors");
1278 }
1279
1280 void BGFillRect(HDC hdc,RECT *R,HBRUSH brush)
1281 {
1282 if(!BGEnable)
1283 FillRect(hdc,R,brush);
1284 else
1285 BitBlt(VTDC,R->left,R->top,R->right - R->left,R->bottom - R->top,hdcBG,R->left,R->top,SRCCOPY);
1286 }
1287
1288 void BGScrollWindow(HWND hwnd,int xa,int ya,RECT *Rect,RECT *ClipRect)
1289 {
1290 if (ts.MaximizedBugTweak) {
1291 // Eterm lookfeel���L���A���������������E�B���h�E���������X�N���[�����g�������B
1292 // �����������A�������E�B���h�E�������������������������P�������B(2008.2.1 doda, yutaka)
1293 if(BGEnable || IsZoomed(hwnd))
1294 InvalidateRect(HVTWin,ClipRect,FALSE);
1295 else
1296 ScrollWindow(hwnd,xa,ya,Rect,ClipRect);
1297 } else {
1298 if(!BGEnable)
1299 ScrollWindow(hwnd,xa,ya,Rect,ClipRect);
1300 else
1301 InvalidateRect(HVTWin,ClipRect,FALSE);
1302 }
1303 }
1304
1305 void BGOnEnterSizeMove(void)
1306 {
1307 int r,g,b;
1308
1309 if(!BGEnable || !BGFastSizeMove)
1310 return;
1311
1312 BGInSizeMove = TRUE;
1313
1314 //�w�i�F����
1315 r = GetRValue(BGDest.color);
1316 g = GetGValue(BGDest.color);
1317 b = GetBValue(BGDest.color);
1318
1319 r = (r * (255 - BGSrc1.alpha) + GetRValue(BGSrc1.color) * BGSrc1.alpha) >> 8;
1320 g = (g * (255 - BGSrc1.alpha) + GetGValue(BGSrc1.color) * BGSrc1.alpha) >> 8;
1321 b = (b * (255 - BGSrc1.alpha) + GetBValue(BGSrc1.color) * BGSrc1.alpha) >> 8;
1322
1323 r = (r * (255 - BGSrc2.alpha) + GetRValue(BGSrc2.color) * BGSrc2.alpha) >> 8;
1324 g = (g * (255 - BGSrc2.alpha) + GetGValue(BGSrc2.color) * BGSrc2.alpha) >> 8;
1325 b = (b * (255 - BGSrc2.alpha) + GetBValue(BGSrc2.color) * BGSrc2.alpha) >> 8;
1326
1327 BGBrushInSizeMove = CreateSolidBrush(RGB(r,g,b));
1328 }
1329
1330 void BGOnExitSizeMove(void)
1331 {
1332 if(!BGEnable || !BGFastSizeMove)
1333 return;
1334
1335 BGInSizeMove = FALSE;
1336
1337 BGSetupPrimary(TRUE);
1338 InvalidateRect(HVTWin,NULL,FALSE);
1339
1340 //�u���V������
1341 if(BGBrushInSizeMove)
1342 {
1343 DeleteObject(BGBrushInSizeMove);
1344 BGBrushInSizeMove = NULL;
1345 }
1346 }
1347
1348 void BGOnSettingChange(void)
1349 {
1350 if(!BGEnable)
1351 return;
1352
1353 CRTWidth = GetSystemMetrics(SM_CXSCREEN);
1354 CRTHeight = GetSystemMetrics(SM_CYSCREEN);
1355
1356 //���� or �w�i���v�����[�h
1357 BGPreloadSrc(&BGDest);
1358 BGPreloadSrc(&BGSrc1);
1359 BGPreloadSrc(&BGSrc2);
1360
1361 BGSetupPrimary(TRUE);
1362 InvalidateRect(HVTWin,0,FALSE);
1363 }
1364
1365 //-->
1366 #endif // ALPHABLEND_TYPE2
1367
1368 void DispApplyANSIColor() {
1369 int i;
1370
1371 for (i = IdBack ; i <= IdFore+8 ; i++)
1372 ANSIColor[i] = ts.ANSIColor[i];
1373
1374 if ((ts.ColorFlag & CF_USETEXTCOLOR)!=0) {
1375 #ifdef ALPHABLEND_TYPE2
1376 ANSIColor[IdBack ] = BGVTColor[1]; // use background color for "Black"
1377 ANSIColor[IdFore ] = BGVTColor[0]; // use text color for "white"
1378 #else
1379 ANSIColor[IdBack ] = ts.VTColor[1]; // use background color for "Black"
1380 ANSIColor[IdFore ] = ts.VTColor[0]; // use text color for "white"
1381 #endif
1382 }
1383 }
1384
1385 void InitColorTable()
1386 {
1387 #ifndef NO_ANSI_COLOR_EXTENSION
1388 DispApplyANSIColor();
1389 #else /* NO_ANSI_COLOR_EXTENSION */
1390 ANSIColor[IdBack ] = RGB( 0, 0, 0);
1391 ANSIColor[IdRed ] = RGB(255, 0, 0);
1392 ANSIColor[IdGreen] = RGB( 0,255, 0);
1393 ANSIColor[IdYellow] = RGB(255,255, 0);
1394 ANSIColor[IdBlue] = RGB( 0, 0,255);
1395 ANSIColor[IdMagenta] = RGB(255, 0,255);
1396 ANSIColor[IdCyan] = RGB( 0,255,255);
1397 ANSIColor[IdFore ] = RGB(255,255,255);
1398 ANSIColor[IdBack+8] = RGB(128,128,128);
1399 ANSIColor[IdRed+8] = RGB(128, 0, 0);
1400 ANSIColor[IdGreen+8] = RGB( 0,128, 0);
1401 ANSIColor[IdYellow+8] = RGB(128,128, 0);
1402 ANSIColor[IdBlue+8] = RGB( 0, 0,128);
1403 ANSIColor[IdMagenta+8] = RGB(128, 0,128);
1404 ANSIColor[IdCyan+8] = RGB( 0,128,128);
1405 ANSIColor[IdFore+8] = RGB(192,192,192);
1406 #endif /* NO_ANSI_COLOR_EXTENSION */
1407 ANSIColor[16] = RGB(0,0,0);
1408 ANSIColor[17] = RGB(0,0,95);
1409 ANSIColor[18] = RGB(0,0,135);
1410 ANSIColor[19] = RGB(0,0,175);
1411 ANSIColor[20] = RGB(0,0,215);
1412 ANSIColor[21] = RGB(0,0,255);
1413 ANSIColor[22] = RGB(0,95,0);
1414 ANSIColor[23] = RGB(0,95,95);
1415 ANSIColor[24] = RGB(0,95,135);
1416 ANSIColor[25] = RGB(0,95,175);
1417 ANSIColor[26] = RGB(0,95,215);
1418 ANSIColor[27] = RGB(0,95,255);
1419 ANSIColor[28] = RGB(0,135,0);
1420 ANSIColor[29] = RGB(0,135,95);
1421 ANSIColor[30] = RGB(0,135,135);
1422 ANSIColor[31] = RGB(0,135,175);
1423 ANSIColor[32] = RGB(0,135,215);
1424 ANSIColor[33] = RGB(0,135,255);
1425 ANSIColor[34] = RGB(0,175,0);
1426 ANSIColor[35] = RGB(0,175,95);
1427 ANSIColor[36] = RGB(0,175,135);
1428 ANSIColor[37] = RGB(0,175,175);
1429 ANSIColor[38] = RGB(0,175,215);
1430 ANSIColor[39] = RGB(0,175,255);
1431 ANSIColor[40] = RGB(0,215,0);
1432 ANSIColor[41] = RGB(0,215,95);
1433 ANSIColor[42] = RGB(0,215,135);
1434 ANSIColor[43] = RGB(0,215,175);
1435 ANSIColor[44] = RGB(0,215,215);
1436 ANSIColor[45] = RGB(0,215,255);
1437 ANSIColor[46] = RGB(0,255,0);
1438 ANSIColor[47] = RGB(0,255,95);
1439 ANSIColor[48] = RGB(0,255,135);
1440 ANSIColor[49] = RGB(0,255,175);
1441 ANSIColor[50] = RGB(0,255,215);
1442 ANSIColor[51] = RGB(0,255,255);
1443 ANSIColor[52] = RGB(95,0,0);
1444 ANSIColor[53] = RGB(95,0,95);
1445 ANSIColor[54] = RGB(95,0,135);
1446 ANSIColor[55] = RGB(95,0,175);
1447 ANSIColor[56] = RGB(95,0,215);
1448 ANSIColor[57] = RGB(95,0,255);
1449 ANSIColor[58] = RGB(95,95,0);
1450 ANSIColor[59] = RGB(95,95,95);
1451 ANSIColor[60] = RGB(95,95,135);
1452 ANSIColor[61] = RGB(95,95,175);
1453 ANSIColor[62] = RGB(95,95,215);
1454 ANSIColor[63] = RGB(95,95,255);
1455 ANSIColor[64] = RGB(95,135,0);
1456 ANSIColor[65] = RGB(95,135,95);
1457 ANSIColor[66] = RGB(95,135,135);
1458 ANSIColor[67] = RGB(95,135,175);
1459 ANSIColor[68] = RGB(95,135,215);
1460 ANSIColor[69] = RGB(95,135,255);
1461 ANSIColor[70] = RGB(95,175,0);
1462 ANSIColor[71] = RGB(95,175,95);
1463 ANSIColor[72] = RGB(95,175,135);
1464 ANSIColor[73] = RGB(95,175,175);
1465 ANSIColor[74] = RGB(95,175,215);
1466 ANSIColor[75] = RGB(95,175,255);
1467 ANSIColor[76] = RGB(95,215,0);
1468 ANSIColor[77] = RGB(95,215,95);
1469 ANSIColor[78] = RGB(95,215,135);
1470 ANSIColor[79] = RGB(95,215,175);
1471 ANSIColor[80] = RGB(95,215,215);
1472 ANSIColor[81] = RGB(95,215,255);
1473 ANSIColor[82] = RGB(95,255,0);
1474 ANSIColor[83] = RGB(95,255,95);
1475 ANSIColor[84] = RGB(95,255,135);
1476 ANSIColor[85] = RGB(95,255,175);
1477 ANSIColor[86] = RGB(95,255,215);
1478 ANSIColor[87] = RGB(95,255,255);
1479 ANSIColor[88] = RGB(135,0,0);
1480 ANSIColor[89] = RGB(135,0,95);
1481 ANSIColor[90] = RGB(135,0,135);
1482 ANSIColor[91] = RGB(135,0,175);
1483 ANSIColor[92] = RGB(135,0,215);
1484 ANSIColor[93] = RGB(135,0,255);
1485 ANSIColor[94] = RGB(135,95,0);
1486 ANSIColor[95] = RGB(135,95,95);
1487 ANSIColor[96] = RGB(135,95,135);
1488 ANSIColor[97] = RGB(135,95,175);
1489 ANSIColor[98] = RGB(135,95,215);
1490 ANSIColor[99] = RGB(135,95,255);
1491 ANSIColor[100] = RGB(135,135,0);
1492 ANSIColor[101] = RGB(135,135,95);
1493 ANSIColor[102] = RGB(135,135,135);
1494 ANSIColor[103] = RGB(135,135,175);
1495 ANSIColor[104] = RGB(135,135,215);
1496 ANSIColor[105] = RGB(135,135,255);
1497 ANSIColor[106] = RGB(135,175,0);
1498 ANSIColor[107] = RGB(135,175,95);
1499 ANSIColor[108] = RGB(135,175,135);
1500 ANSIColor[109] = RGB(135,175,175);
1501 ANSIColor[110] = RGB(135,175,215);
1502 ANSIColor[111] = RGB(135,175,255);
1503 ANSIColor[112] = RGB(135,215,0);
1504 ANSIColor[113] = RGB(135,215,95);
1505 ANSIColor[114] = RGB(135,215,135);
1506 ANSIColor[115] = RGB(135,215,175);
1507 ANSIColor[116] = RGB(135,215,215);
1508 ANSIColor[117] = RGB(135,215,255);
1509 ANSIColor[118] = RGB(135,255,0);
1510 ANSIColor[119] = RGB(135,255,95);
1511 ANSIColor[120] = RGB(135,255,135);
1512 ANSIColor[121] = RGB(135,255,175);
1513 ANSIColor[122] = RGB(135,255,215);
1514 ANSIColor[123] = RGB(135,255,255);
1515 ANSIColor[124] = RGB(175,0,0);
1516 ANSIColor[125] = RGB(175,0,95);
1517 ANSIColor[126] = RGB(175,0,135);
1518 ANSIColor[127] = RGB(175,0,175);
1519 ANSIColor[128] = RGB(175,0,215);
1520 ANSIColor[129] = RGB(175,0,255);
1521 ANSIColor[130] = RGB(175,95,0);
1522 ANSIColor[131] = RGB(175,95,95);
1523 ANSIColor[132] = RGB(175,95,135);
1524 ANSIColor[133] = RGB(175,95,175);
1525 ANSIColor[134] = RGB(175,95,215);
1526 ANSIColor[135] = RGB(175,95,255);
1527 ANSIColor[136] = RGB(175,135,0);
1528 ANSIColor[137] = RGB(175,135,95);
1529 ANSIColor[138] = RGB(175,135,135);
1530 ANSIColor[139] = RGB(175,135,175);
1531 ANSIColor[140] = RGB(175,135,215);
1532 ANSIColor[141] = RGB(175,135,255);
1533 ANSIColor[142] = RGB(175,175,0);
1534 ANSIColor[143] = RGB(175,175,95);
1535 ANSIColor[144] = RGB(175,175,135);
1536 ANSIColor[145] = RGB(175,175,175);
1537 ANSIColor[146] = RGB(175,175,215);
1538 ANSIColor[147] = RGB(175,175,255);
1539 ANSIColor[148] = RGB(175,215,0);
1540 ANSIColor[149] = RGB(175,215,95);
1541 ANSIColor[150] = RGB(175,215,135);
1542 ANSIColor[151] = RGB(175,215,175);
1543 ANSIColor[152] = RGB(175,215,215);
1544 ANSIColor[153] = RGB(175,215,255);
1545 ANSIColor[154] = RGB(175,255,0);
1546 ANSIColor[155] = RGB(175,255,95);
1547 ANSIColor[156] = RGB(175,255,135);
1548 ANSIColor[157] = RGB(175,255,175);
1549 ANSIColor[158] = RGB(175,255,215);
1550 ANSIColor[159] = RGB(175,255,255);
1551 ANSIColor[160] = RGB(215,0,0);
1552 ANSIColor[161] = RGB(215,0,95);
1553 ANSIColor[162] = RGB(215,0,135);
1554 ANSIColor[163] = RGB(215,0,175);
1555 ANSIColor[164] = RGB(215,0,215);
1556 ANSIColor[165] = RGB(215,0,255);
1557 ANSIColor[166] = RGB(215,95,0);
1558 ANSIColor[167] = RGB(215,95,95);
1559 ANSIColor[168] = RGB(215,95,135);
1560 ANSIColor[169] = RGB(215,95,175);
1561 ANSIColor[170] = RGB(215,95,215);
1562 ANSIColor[171] = RGB(215,95,255);
1563 ANSIColor[172] = RGB(215,135,0);
1564 ANSIColor[173] = RGB(215,135,95);
1565 ANSIColor[174] = RGB(215,135,135);
1566 ANSIColor[175] = RGB(215,135,175);
1567 ANSIColor[176] = RGB(215,135,215);
1568 ANSIColor[177] = RGB(215,135,255);
1569 ANSIColor[178] = RGB(215,175,0);
1570 ANSIColor[179] = RGB(215,175,95);
1571 ANSIColor[180] = RGB(215,175,135);
1572 ANSIColor[181] = RGB(215,175,175);
1573 ANSIColor[182] = RGB(215,175,215);
1574 ANSIColor[183] = RGB(215,175,255);
1575 ANSIColor[184] = RGB(215,215,0);
1576 ANSIColor[185] = RGB(215,215,95);
1577 ANSIColor[186] = RGB(215,215,135);
1578 ANSIColor[187] = RGB(215,215,175);
1579 ANSIColor[188] = RGB(215,215,215);
1580 ANSIColor[189] = RGB(215,215,255);
1581 ANSIColor[190] = RGB(215,255,0);
1582 ANSIColor[191] = RGB(215,255,95);
1583 ANSIColor[192] = RGB(215,255,135);
1584 ANSIColor[193] = RGB(215,255,175);
1585 ANSIColor[194] = RGB(215,255,215);
1586 ANSIColor[195] = RGB(215,255,255);
1587 ANSIColor[196] = RGB(255,0,0);
1588 ANSIColor[197] = RGB(255,0,95);
1589 ANSIColor[198] = RGB(255,0,135);
1590 ANSIColor[199] = RGB(255,0,175);
1591 ANSIColor[200] = RGB(255,0,215);
1592 ANSIColor[201] = RGB(255,0,255);
1593 ANSIColor[202] = RGB(255,95,0);
1594 ANSIColor[203] = RGB(255,95,95);
1595 ANSIColor[204] = RGB(255,95,135);
1596 ANSIColor[205] = RGB(255,95,175);
1597 ANSIColor[206] = RGB(255,95,215);
1598 ANSIColor[207] = RGB(255,95,255);
1599 ANSIColor[208] = RGB(255,135,0);
1600 ANSIColor[209] = RGB(255,135,95);
1601 ANSIColor[210] = RGB(255,135,135);
1602 ANSIColor[211] = RGB(255,135,175);
1603 ANSIColor[212] = RGB(255,135,215);
1604 ANSIColor[213] = RGB(255,135,255);
1605 ANSIColor[214] = RGB(255,175,0);
1606 ANSIColor[215] = RGB(255,175,95);
1607 ANSIColor[216] = RGB(255,175,135);
1608 ANSIColor[217] = RGB(255,175,175);
1609 ANSIColor[218] = RGB(255,175,215);
1610 ANSIColor[219] = RGB(255,175,255);
1611 ANSIColor[220] = RGB(255,215,0);
1612 ANSIColor[221] = RGB(255,215,95);
1613 ANSIColor[222] = RGB(255,215,135);
1614 ANSIColor[223] = RGB(255,215,175);
1615 ANSIColor[224] = RGB(255,215,215);
1616 ANSIColor[225] = RGB(255,215,255);
1617 ANSIColor[226] = RGB(255,255,0);
1618 ANSIColor[227] = RGB(255,255,95);
1619 ANSIColor[228] = RGB(255,255,135);
1620 ANSIColor[229] = RGB(255,255,175);
1621 ANSIColor[230] = RGB(255,255,215);
1622 ANSIColor[231] = RGB(255,255,255);
1623 ANSIColor[232] = RGB(8,8,8);
1624 ANSIColor[233] = RGB(18,18,18);
1625 ANSIColor[234] = RGB(28,28,28);
1626 ANSIColor[235] = RGB(38,38,38);
1627 ANSIColor[236] = RGB(48,48,48);
1628 ANSIColor[237] = RGB(58,58,58);
1629 ANSIColor[238] = RGB(68,68,68);
1630 ANSIColor[239] = RGB(78,78,78);
1631 ANSIColor[240] = RGB(88,88,88);
1632 ANSIColor[241] = RGB(98,98,98);
1633 ANSIColor[242] = RGB(108,108,108);
1634 ANSIColor[243] = RGB(118,118,118);
1635 ANSIColor[244] = RGB(128,128,128);
1636 ANSIColor[245] = RGB(138,138,138);
1637 ANSIColor[246] = RGB(148,148,148);
1638 ANSIColor[247] = RGB(158,158,158);
1639 ANSIColor[248] = RGB(168,168,168);
1640 ANSIColor[249] = RGB(178,178,178);
1641 ANSIColor[250] = RGB(188,188,188);
1642 ANSIColor[251] = RGB(198,198,198);
1643 ANSIColor[252] = RGB(208,208,208);
1644 ANSIColor[253] = RGB(218,218,218);
1645 ANSIColor[254] = RGB(228,228,228);
1646 ANSIColor[255] = RGB(238,238,238);
1647
1648 if ((ts.ColorFlag & CF_USETEXTCOLOR)!=0) {
1649 #ifdef ALPHABLEND_TYPE2
1650 ANSIColor[IdBack ] = BGVTColor[1]; // use background color for "Black"
1651 ANSIColor[IdFore ] = BGVTColor[0]; // use text color for "white"
1652 #else
1653 ANSIColor[IdBack ] = ts.VTColor[1]; // use background color for "Black"
1654 ANSIColor[IdFore ] = ts.VTColor[0]; // use text color for "white"
1655 #endif
1656 }
1657 }
1658
1659 void DispSetNearestColors(int start, int end, HDC DispCtx) {
1660 HDC TmpDC;
1661 int i;
1662
1663 if (DispCtx) {
1664 TmpDC = DispCtx;
1665 }
1666 else {
1667 TmpDC = GetDC(NULL);
1668 }
1669
1670 for (i = start ; i <= end; i++)
1671 ANSIColor[i] = GetNearestColor(TmpDC, ANSIColor[i]);
1672
1673 if (!DispCtx) {
1674 ReleaseDC(NULL, TmpDC);
1675 }
1676 }
1677
1678 void InitDisp()
1679 {
1680 HDC TmpDC;
1681 BOOL bMultiDisplaySupport = FALSE;
1682
1683 TmpDC = GetDC(NULL);
1684
1685 #ifdef ALPHABLEND_TYPE2
1686 CRTWidth = GetSystemMetrics(SM_CXSCREEN);
1687 CRTHeight = GetSystemMetrics(SM_CYSCREEN);
1688
1689 BGInitialize();
1690 #else
1691 InitColorTable();
1692 #endif // ALPHABLEND_TYPE2
1693
1694 DispSetNearestColors(IdBack, 255, TmpDC);
1695
1696 /* background paintbrush */
1697 Background = CreateSolidBrush(ts.VTColor[1]);
1698 /* CRT width & height */
1699 {
1700 OSVERSIONINFO ver;
1701 ZeroMemory( &ver, sizeof(ver) );
1702 ver.dwOSVersionInfoSize = sizeof(ver);
1703 GetVersionEx( &ver );
1704 switch( ver.dwPlatformId ) {
1705 // Windows 9x �� NT ��������
1706 case VER_PLATFORM_WIN32_WINDOWS:
1707 if( ver.dwMajorVersion > 4 ||
1708 (ver.dwMajorVersion == 4 && ver.dwMinorVersion >= 10) ) // Windows 98 or later
1709 bMultiDisplaySupport = TRUE;
1710 break;
1711 case VER_PLATFORM_WIN32_NT:
1712 if( ver.dwMajorVersion >= 5 ) // Windows 2000 or later
1713 bMultiDisplaySupport = TRUE;
1714 break;
1715 default:
1716 break;
1717 }
1718 }
1719 if( bMultiDisplaySupport ) {
1720 VirtualScreen.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
1721 VirtualScreen.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
1722 VirtualScreen.right = VirtualScreen.left + GetSystemMetrics(SM_CXVIRTUALSCREEN);
1723 VirtualScreen.bottom = VirtualScreen.top + GetSystemMetrics(SM_CYVIRTUALSCREEN);
1724 } else {
1725 VirtualScreen.left = 0;
1726 VirtualScreen.top = 0;
1727 VirtualScreen.right = GetDeviceCaps(TmpDC,HORZRES);
1728 VirtualScreen.bottom = GetDeviceCaps(TmpDC,VERTRES);
1729 }
1730
1731 ReleaseDC(NULL, TmpDC);
1732
1733 if ( (ts.VTPos.x > VirtualScreen.right) || (ts.VTPos.y > VirtualScreen.bottom) )
1734 {
1735 ts.VTPos.x = CW_USEDEFAULT;
1736 ts.VTPos.y = CW_USEDEFAULT;
1737 }
1738 else if ( (ts.VTPos.x < VirtualScreen.left-20) || (ts.VTPos.y < VirtualScreen.top-20) )
1739 {
1740 ts.VTPos.x = CW_USEDEFAULT;
1741 ts.VTPos.y = CW_USEDEFAULT;
1742 }
1743 else {
1744 if ( ts.VTPos.x < VirtualScreen.left ) ts.VTPos.x = VirtualScreen.left;
1745 if ( ts.VTPos.y < VirtualScreen.top ) ts.VTPos.y = VirtualScreen.top;
1746 }
1747
1748 if ( (ts.TEKPos.x > VirtualScreen.right) || (ts.TEKPos.y > VirtualScreen.bottom) )
1749 {
1750 ts.TEKPos.x = CW_USEDEFAULT;
1751 ts.TEKPos.y = CW_USEDEFAULT;
1752 }
1753 else if ( (ts.TEKPos.x < VirtualScreen.left-20) || (ts.TEKPos.y < VirtualScreen.top-20) )
1754 {
1755 ts.TEKPos.x = CW_USEDEFAULT;
1756 ts.TEKPos.y = CW_USEDEFAULT;
1757 }
1758 else {
1759 if ( ts.TEKPos.x < VirtualScreen.left ) ts.TEKPos.x = VirtualScreen.left;
1760 if ( ts.TEKPos.y < VirtualScreen.top ) ts.TEKPos.y = VirtualScreen.top;
1761 }
1762 }
1763
1764 void EndDisp()
1765 {
1766 int i, j;
1767
1768 if (VTDC!=NULL) DispReleaseDC();
1769
1770 /* Delete fonts */
1771 for (i = 0 ; i <= AttrFontMask; i++)
1772 {
1773 for (j = i+1 ; j <= AttrFontMask ; j++)
1774 if (VTFont[j]==VTFont[i])
1775 VTFont[j] = 0;
1776 if (VTFont[i]!=0) DeleteObject(VTFont[i]);
1777 }
1778
1779 if (Background!=0)
1780 {
1781 DeleteObject(Background);
1782 Background = 0;
1783 }
1784
1785 #ifdef ALPHABLEND_TYPE2
1786 //<!--by AKASI
1787 BGDestruct();
1788 //-->
1789 #endif // ALPHABLEND_TYPE2
1790
1791 }
1792
1793 void DispReset()
1794 {
1795 /* Cursor */
1796 CursorX = 0;
1797 CursorY = 0;
1798
1799 /* Scroll status */
1800 ScrollCount = 0;
1801 dScroll = 0;
1802
1803 if (IsCaretOn()) CaretOn();
1804 DispEnableCaret(TRUE); // enable caret
1805 }
1806
1807 void DispConvWinToScreen
1808 (int Xw, int Yw, int *Xs, int *Ys, PBOOL Right)
1809 // Converts window coordinate to screen cordinate
1810 // Xs: horizontal position in window coordinate (pixels)
1811 // Ys: vertical
1812 // Output
1813 // Xs, Ys: screen coordinate
1814 // Right: TRUE if the (Xs,Ys) is on the right half of
1815 // a character cell.
1816 {
1817 if (Xs!=NULL)
1818 *Xs = Xw / FontWidth + WinOrgX;
1819 *Ys = Yw / FontHeight + WinOrgY;
1820 if ((Xs!=NULL) && (Right!=NULL))
1821 *Right = (Xw - (*Xs-WinOrgX)*FontWidth) >= FontWidth/2;
1822 }
1823
1824 void DispConvScreenToWin
1825 (int Xs, int Ys, int *Xw, int *Yw)
1826 // Converts screen coordinate to window cordinate
1827 // Xs: horizontal position in screen coordinate (characters)
1828 // Ys: vertical
1829 // Output
1830 // Xw, Yw: window coordinate
1831 {
1832 if (Xw!=NULL)
1833 *Xw = (Xs - WinOrgX) * FontWidth;
1834 if (Yw!=NULL)
1835 *Yw = (Ys - WinOrgY) * FontHeight;
1836 }
1837
1838 void SetLogFont()
1839 {
1840 memset(&VTlf, 0, sizeof(LOGFONT));
1841 VTlf.lfWeight = FW_NORMAL;
1842 VTlf.lfItalic = 0;
1843 VTlf.lfUnderline = 0;
1844 VTlf.lfStrikeOut = 0;
1845 VTlf.lfWidth = ts.VTFontSize.x;
1846 VTlf.lfHeight = ts.VTFontSize.y;
1847 VTlf.lfCharSet = ts.VTFontCharSet;
1848 VTlf.lfOutPrecision = OUT_CHARACTER_PRECIS;
1849 VTlf.lfClipPrecision = CLIP_CHARACTER_PRECIS;
1850 VTlf.lfQuality = DEFAULT_QUALITY;
1851 VTlf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
1852 strncpy_s(VTlf.lfFaceName, sizeof(VTlf.lfFaceName),ts.VTFont, _TRUNCATE);
1853 }
1854
1855 void ChangeFont()
1856 {
1857 int i, j;
1858 TEXTMETRIC Metrics;
1859 HDC TmpDC;
1860
1861 /* Delete Old Fonts */
1862 for (i = 0 ; i <= AttrFontMask ; i++)
1863 {
1864 for (j = i+1 ; j <= AttrFontMask ; j++)
1865 if (VTFont[j]==VTFont[i])
1866 VTFont[j] = 0;
1867 if (VTFont[i]!=0)
1868 DeleteObject(VTFont[i]);
1869 }
1870
1871 /* Normal Font */
1872 SetLogFont();
1873 VTFont[0] = CreateFontIndirect(&VTlf);
1874
1875 /* set IME font */
1876 SetConversionLogFont(&VTlf);
1877
1878 TmpDC = GetDC(HVTWin);
1879
1880 SelectObject(TmpDC, VTFont[0]);
1881 GetTextMetrics(TmpDC, &Metrics);
1882 FontWidth = Metrics.tmAveCharWidth + ts.FontDW;
1883 FontHeight = Metrics.tmHeight + ts.FontDH;
1884
1885 ReleaseDC(HVTWin,TmpDC);
1886
1887 /* Underline */
1888 VTlf.lfUnderline = 1;
1889 VTFont[AttrUnder] = CreateFontIndirect(&VTlf);
1890
1891 if (ts.EnableBold>0)
1892 {
1893 /* Bold */
1894 VTlf.lfUnderline = 0;
1895 VTlf.lfWeight = FW_BOLD;
1896 VTFont[AttrBold] = CreateFontIndirect(&VTlf);
1897 /* Bold + Underline */
1898 VTlf.lfUnderline = 1;
1899 VTFont[AttrBold | AttrUnder] = CreateFontIndirect(&VTlf);
1900 }
1901 else {
1902 VTFont[AttrBold] = VTFont[AttrDefault];
1903 VTFont[AttrBold | AttrUnder] = VTFont[AttrUnder];
1904 }
1905
1906 /* Special font */
1907 VTlf.lfWeight = FW_NORMAL;
1908 VTlf.lfUnderline = 0;
1909 VTlf.lfWidth = FontWidth + 1; /* adjust width */
1910 VTlf.lfHeight = FontHeight;
1911 VTlf.lfCharSet = SYMBOL_CHARSET;
1912
1913 strncpy_s(VTlf.lfFaceName, sizeof(VTlf.lfFaceName),"Tera Special", _TRUNCATE);
1914 VTFont[AttrSpecial] = CreateFontIndirect(&VTlf);
1915 VTFont[AttrSpecial | AttrBold] = VTFont[AttrSpecial];
1916 VTFont[AttrSpecial | AttrUnder] = VTFont[AttrSpecial];
1917 VTFont[AttrSpecial | AttrBold | AttrUnder] = VTFont[AttrSpecial];
1918
1919 SetLogFont();
1920
1921 for (i = 0 ; i <= 255; i++)
1922 Dx[i] = FontWidth;
1923 }
1924
1925 void ResetIME()
1926 {
1927 /* reset language for communication */
1928 cv.Language = ts.Language;
1929
1930 /* reset IME */
1931 if ((ts.Language==IdJapanese) || (ts.Language==IdKorean)) //HKS
1932 {
1933 if (ts.UseIME==0)
1934 FreeIME();
1935 else if (! LoadIME())
1936 ts.UseIME = 0;
1937
1938 if (ts.UseIME>0)
1939 {
1940 if (ts.IMEInline>0)
1941 SetConversionLogFont(&VTlf);
1942 else
1943 SetConversionWindow(HVTWin,-1,0);
1944 }
1945 }
1946 else
1947 FreeIME();
1948
1949 if (IsCaretOn()) CaretOn();
1950 }
1951
1952 void ChangeCaret()
1953 {
1954 UINT T;
1955
1956 if (! Active) return;
1957 if (CaretEnabled)
1958 {
1959 DestroyCaret();
1960 switch (ts.CursorShape) {
1961 case IdVCur:
1962 CreateCaret(HVTWin, 0, CurWidth, FontHeight);
1963 break;
1964 case IdHCur:
1965 CreateCaret(HVTWin, 0, FontWidth, CurWidth);
1966 break;
1967 }
1968 CaretStatus = 1;
1969 }
1970 CaretOn();
1971 if (CaretEnabled &&
1972 (ts.NonblinkingCursor!=0))
1973 {
1974 T = GetCaretBlinkTime() * 2 / 3;
1975 SetTimer(HVTWin,IdCaretTimer,T,NULL);
1976 }
1977 }
1978
1979 // WM_KILLFOCUS�������������J�[�\�����������`��
1980 void CaretKillFocus(BOOL show)
1981 {
1982 int CaretX, CaretY;
1983 POINT p[5];
1984 HPEN oldpen;
1985 HDC hdc;
1986
1987 if (ts.KillFocusCursor == 0)
1988 return;
1989
1990 // Eterm lookfeel������������������
1991 #ifdef ALPHABLEND_TYPE2
1992 if (BGEnable)
1993 return;
1994 #endif // ALPHABLEND_TYPE2
1995
1996 /* Get Device Context */
1997 DispInitDC();
1998 hdc = VTDC;
1999
2000 CaretX = (CursorX-WinOrgX)*FontWidth;
2001 CaretY = (CursorY-WinOrgY)*FontHeight;
2002
2003 p[0].x = CaretX;
2004 p[0].y = CaretY;
2005 p[1].x = CaretX;
2006 p[1].y = CaretY + FontHeight - 1;
2007 if (CursorOnDBCS)
2008 p[2].x = CaretX + FontWidth*2 - 1;
2009 else
2010 p[2].x = CaretX + FontWidth - 1;
2011 p[2].y = CaretY + FontHeight - 1;
2012 if (CursorOnDBCS)
2013 p[3].x = CaretX + FontWidth*2 - 1;
2014 else
2015 p[3].x = CaretX + FontWidth - 1;
2016 p[3].y = CaretY;
2017 p[4].x = CaretX;
2018 p[4].y = CaretY;
2019
2020 if (show) { // �|���S���J�[�\�����\���i���t�H�[�J�X���j
2021 oldpen = SelectObject(hdc, CreatePen(PS_SOLID, 0, ts.VTColor[0]));
2022 } else {
2023 oldpen = SelectObject(hdc, CreatePen(PS_SOLID, 0, ts.VTColor[1]));
2024 }
2025 Polyline(VTDC, p, 5);
2026 oldpen = SelectObject(hdc, oldpen);
2027 DeleteObject(oldpen);
2028
2029 /* release device context */
2030 DispReleaseDC();
2031 }
2032
2033 // �|���S���J�[�\�����������������A�������������������`�������B
2034 //
2035 // CaretOff()�����������������BCaretOff()�������������A�������A�����o���������A
2036 // stack overflow�������B
2037 void UpdateCaretKillFocus(BOOL enforce)
2038 {
2039 int CaretX, CaretY;
2040 RECT rc;
2041
2042 CaretX = (CursorX-WinOrgX)*FontWidth;
2043 CaretY = (CursorY-WinOrgY)*FontHeight;
2044
2045 if (ts.KillFocusCursor == 0)
2046 return;
2047
2048 // Eterm lookfeel������������������
2049 #ifdef ALPHABLEND_TYPE2
2050 if (BGEnable)
2051 return;
2052 #endif // ALPHABLEND_TYPE2
2053
2054 if (enforce == TRUE || !Active) {
2055 rc.left = CaretX;
2056 rc.top = CaretY;
2057 if (CursorOnDBCS)
2058 rc.right = CaretX + FontWidth*2;
2059 else
2060 rc.right = CaretX + FontWidth;
2061 rc.bottom = CaretY + FontHeight;
2062 // �w��������1�s�N�Z�����������������`������������
2063 // rc �� right, bottom ��1�s�N�Z�����������������B
2064 InvalidateRect(HVTWin, &rc, FALSE);
2065 }
2066 }
2067
2068 void CaretOn()
2069 // Turn on the cursor
2070 {
2071 int CaretX, CaretY, H;
2072
2073 if (ts.KillFocusCursor == 0 && !Active)
2074 return;
2075
2076 CaretX = (CursorX-WinOrgX)*FontWidth;
2077 CaretY = (CursorY-WinOrgY)*FontHeight;
2078
2079 if ((ts.Language==IdJapanese) &&
2080 CanUseIME() && (ts.IMEInline>0))
2081 /* set IME conversion window pos. & font */
2082 SetConversionWindow(HVTWin,CaretX,CaretY);
2083
2084 if (! CaretEnabled) return;
2085
2086 if (Active) {
2087 if (ts.CursorShape!=IdVCur)
2088 {
2089 if (ts.CursorShape==IdHCur)
2090 {
2091 CaretY = CaretY+FontHeight-CurWidth;
2092 H = CurWidth;
2093 }
2094 else H = FontHeight;
2095
2096 DestroyCaret();
2097 if (CursorOnDBCS)
2098 CreateCaret(HVTWin, 0, FontWidth*2, H); /* double width caret */
2099 else
2100 CreateCaret(HVTWin, 0, FontWidth, H); /* single width caret */
2101 CaretStatus = 1;
2102 }
2103
2104 SetCaretPos(CaretX,CaretY);
2105 }
2106
2107 while (CaretStatus > 0)
2108 {
2109 if (! Active) {
2110 CaretKillFocus(TRUE);
2111 } else {
2112 ShowCaret(HVTWin);
2113 }
2114 CaretStatus--;
2115 }
2116
2117 }
2118
2119 void CaretOff()
2120 {
2121 if (ts.KillFocusCursor == 0 && !Active)
2122 return;
2123
2124 if (CaretStatus == 0)
2125 {
2126 if (! Active) {
2127 CaretKillFocus(FALSE);
2128 } else {
2129 HideCaret(HVTWin);
2130 }
2131 CaretStatus++;
2132 }
2133 }
2134
2135 void DispDestroyCaret()
2136 {
2137 DestroyCaret();
2138 if (ts.NonblinkingCursor!=0)
2139 KillTimer(HVTWin,IdCaretTimer);
2140 }
2141
2142 BOOL IsCaretOn()
2143 // check if caret is on
2144 {
2145 // ���A�N�e�B�u�i�t�H�[�J�X�����j�����������������A�J�[�\���`�����s�����������A
2146 // 2���������������������B(2008.1.24 yutaka)
2147 if (ts.KillFocusCursor == 0)
2148 return (( Active && (CaretStatus==0)) );
2149 else
2150 return ((Active && (CaretStatus==0)) || (!Active && (CaretStatus==0)));
2151 }
2152
2153 void DispEnableCaret(BOOL On)
2154 {
2155 if (! On) CaretOff();
2156 CaretEnabled = On;
2157 }
2158
2159 BOOL IsCaretEnabled()
2160 {
2161 return CaretEnabled;
2162 }
2163
2164 void DispSetCaretWidth(BOOL DW)
2165 {
2166 /* TRUE if cursor is on a DBCS character */
2167 CursorOnDBCS = DW;
2168 }
2169
2170 void DispChangeWinSize(int Nx, int Ny)
2171 {
2172 LONG W,H,dW,dH;
2173 RECT R;
2174
2175 if (SaveWinSize)
2176 {
2177 WinWidthOld = WinWidth;
2178 WinHeightOld = WinHeight;
2179 SaveWinSize = FALSE;
2180 }
2181 else {
2182 WinWidthOld = NumOfColumns;
2183 WinHeightOld = NumOfLines;
2184 }
2185
2186 WinWidth = Nx;
2187 WinHeight = Ny;
2188
2189 ScreenWidth = WinWidth*FontWidth;
2190 ScreenHeight = WinHeight*FontHeight;
2191
2192 AdjustScrollBar();
2193
2194 GetWindowRect(HVTWin,&R);
2195 W = R.right-R.left;
2196 H = R.bottom-R.top;
2197 GetClientRect(HVTWin,&R);
2198 dW = ScreenWidth - R.right + R.left;
2199 dH = ScreenHeight - R.bottom + R.top;
2200
2201 if ((dW!=0) || (dH!=0))
2202 {
2203 AdjustSize = TRUE;
2204
2205 // SWP_NOMOVE ���w�������������������� 0,0 �����f�����A
2206 // �}���`�f�B�X�v���C���������v���C�}�����j�^��
2207 // �������������������C�� (2008.5.29 maya)
2208 //SetWindowPos(HVTWin,HWND_TOP,0,0,W+dW,H+dH,SWP_NOMOVE);
2209
2210 // �}���`�f�B�X�v���C�����������������������A
2211 // �����f�B�X�v���C���E�B���h�E���[�������o���������C�� (2008.5.30 maya)
2212 // �����A���L�������������������������E�B���h�E�������������������o�����B
2213 if (!IsZoomed(HVTWin)) {
2214 SetWindowPos(HVTWin,HWND_TOP,R.left,R.top,W+dW,H+dH,SWP_NOMOVE);
2215 }
2216 }
2217 else
2218 InvalidateRect(HVTWin,NULL,FALSE);
2219 }
2220
2221 void ResizeWindow(int x, int y, int w, int h, int cw, int ch)
2222 {
2223 int dw,dh, NewX, NewY;
2224 POINT Point;
2225
2226 if (! AdjustSize) return;
2227 dw = ScreenWidth - cw;
2228 dh = ScreenHeight - ch;
2229 if ((dw!=0) || (dh!=0)) {
2230 SetWindowPos(HVTWin,HWND_TOP,x,y,w+dw,h+dh,SWP_NOMOVE);
2231 AdjustSize = FALSE;
2232 }
2233 else {
2234 AdjustSize = FALSE;
2235
2236 NewX = x;
2237 NewY = y;
2238 if (x+w > VirtualScreen.right)
2239 {
2240 NewX = VirtualScreen.right-w;
2241 if (NewX < 0) NewX = 0;
2242 }
2243 if (y+h > VirtualScreen.bottom)
2244 {
2245 NewY = VirtualScreen.bottom-h;
2246 if (NewY < 0) NewY = 0;
2247 }
2248 if ((NewX!=x) || (NewY!=y))
2249 SetWindowPos(HVTWin,HWND_TOP,NewX,NewY,w,h,SWP_NOSIZE);
2250
2251 Point.x = 0;
2252 Point.y = ScreenHeight;
2253 ClientToScreen(HVTWin,&Point);
2254 CompletelyVisible = (Point.y <= VirtualScreen.bottom);
2255 if (IsCaretOn()) CaretOn();
2256 }
2257 }
2258
2259 void PaintWindow(HDC PaintDC, RECT PaintRect, BOOL fBkGnd,
2260 int* Xs, int* Ys, int* Xe, int* Ye)
2261 // Paint window with background color &
2262 // convert paint region from window coord. to screen coord.
2263 // Called from WM_PAINT handler
2264 // PaintRect: Paint region in window coordinate
2265 // Return:
2266 // *Xs, *Ys: upper left corner of the region
2267 // in screen coord.
2268 // *Xe, *Ye: lower right
2269 {
2270 if (VTDC!=NULL)
2271 DispReleaseDC();
2272 VTDC = PaintDC;
2273 DCPrevFont = SelectObject(VTDC, VTFont[0]);
2274 DispInitDC();
2275
2276 #ifdef ALPHABLEND_TYPE2
2277 //<!--by AKASI
2278 //if (fBkGnd)
2279 if(!BGEnable && fBkGnd)
2280 //-->
2281 #else
2282 if (fBkGnd)
2283 #endif // ALPHABLEND_TYPE2
2284
2285 FillRect(VTDC, &PaintRect,Background);
2286
2287 *Xs = PaintRect.left / FontWidth + WinOrgX;
2288 *Ys = PaintRect.top / FontHeight + WinOrgY;
2289 *Xe = (PaintRect.right-1) / FontWidth + WinOrgX;
2290 *Ye = (PaintRect.bottom-1) / FontHeight + WinOrgY;
2291 }
2292
2293 void DispEndPaint()
2294 {
2295 if (VTDC==NULL) return;
2296 SelectObject(VTDC,DCPrevFont);
2297 VTDC = NULL;
2298 }
2299
2300 void DispClearWin()
2301 {
2302 InvalidateRect(HVTWin,NULL,FALSE);
2303
2304 ScrollCount = 0;
2305 dScroll = 0;
2306 if (WinHeight > NumOfLines)
2307 DispChangeWinSize(NumOfColumns,NumOfLines);
2308 else {
2309 if ((NumOfLines==WinHeight) && (ts.EnableScrollBuff>0))
2310 {
2311 SetScrollRange(HVTWin,SB_VERT,0,1,FALSE);
2312 }
2313 else
2314 SetScrollRange(HVTWin,SB_VERT,0,NumOfLines-WinHeight,FALSE);
2315
2316 SetScrollPos(HVTWin,SB_HORZ,0,TRUE);
2317 SetScrollPos(HVTWin,SB_VERT,0,TRUE);
2318 }
2319 if (IsCaretOn()) CaretOn();
2320 }
2321
2322 void DispChangeBackground()
2323 {
2324 DispReleaseDC();
2325 if (Background != NULL) DeleteObject(Background);
2326
2327 if ((CurCharAttr.Attr2 & Attr2Back) != 0) {
2328 if ((CurCharAttr.Back<16) && (CurCharAttr.Back&7)!=0)
2329 Background = CreateSolidBrush(ANSIColor[CurCharAttr.Back ^ 8]);
2330 else
2331 Background = CreateSolidBrush(ANSIColor[CurCharAttr.Back]);
2332 }
2333 else {
2334 #ifdef ALPHABLEND_TYPE2
2335 Background = CreateSolidBrush(BGVTColor[1]);
2336 #else
2337 Background = CreateSolidBrush(ts.VTColor[1]);
2338 #endif // ALPHABLEND_TYPE2
2339 }
2340
2341 InvalidateRect(HVTWin,NULL,TRUE);
2342 }
2343
2344 void DispChangeWin()
2345 {
2346 /* Change window caption */
2347 ChangeTitle();
2348
2349 /* Menu bar / Popup menu */
2350 SwitchMenu();
2351
2352 SwitchTitleBar();
2353
2354 /* Change caret shape */
2355 ChangeCaret();
2356
2357 if ((ts.ColorFlag & CF_USETEXTCOLOR)==0)
2358 {
2359 #ifndef NO_ANSI_COLOR_EXTENSION
2360 ANSIColor[IdFore ] = ts.ANSIColor[IdFore ];
2361 ANSIColor[IdBack ] = ts.ANSIColor[IdBack ];
2362 #else /* NO_ANSI_COLOR_EXTENSION */
2363 ANSIColor[IdFore ] = RGB(255,255,255);
2364 ANSIColor[IdBack ] = RGB( 0, 0, 0);
2365 #endif /* NO_ANSI_COLOR_EXTENSION */
2366 }
2367 else { // use text (background) color for "white (black)"
2368 ANSIColor[IdFore ] = ts.VTColor[0];
2369 ANSIColor[IdBack ] = ts.VTColor[1];
2370
2371 #ifdef ALPHABLEND_TYPE2
2372 ANSIColor[IdFore ] = BGVTColor[0];
2373 ANSIColor[IdBack ] = BGVTColor[1];
2374 #endif // ALPHABLEND_TYPE2
2375
2376 }
2377
2378 /* change background color */
2379 DispChangeBackground();
2380 }
2381
2382 void DispInitDC()
2383 {
2384
2385 if (VTDC==NULL)
2386 {
2387 VTDC = GetDC(HVTWin);
2388 DCPrevFont = SelectObject(VTDC, VTFont[0]);
2389 }
2390 else
2391 SelectObject(VTDC, VTFont[0]);
2392
2393 #ifdef ALPHABLEND_TYPE2
2394 SetTextColor(VTDC, BGVTColor[0]);
2395 SetBkColor(VTDC, BGVTColor[1]);
2396 #else
2397 SetTextColor(VTDC, ts.VTColor[0]);
2398 SetBkColor(VTDC, ts.VTColor[1]);
2399 #endif // ALPHABLEND_TYPE2
2400
2401 SetBkMode(VTDC,OPAQUE);
2402 DCAttr = DefCharAttr;
2403 DCReverse = FALSE;
2404
2405 #ifdef ALPHABLEND_TYPE2
2406 //<!--by AKASI
2407 BGReverseText = FALSE;
2408 //-->
2409 #endif // ALPHABLEND_TYPE2
2410 }
2411
2412 void DispReleaseDC()
2413 {
2414 if (VTDC==NULL) return;
2415 SelectObject(VTDC, DCPrevFont);
2416 ReleaseDC(HVTWin,VTDC);
2417 VTDC = NULL;
2418 }
2419
2420 void DispSetupDC(TCharAttr Attr, BOOL Reverse)
2421 // Setup device context
2422 // Attr: character attributes
2423 // Reverse: true if text is selected (reversed) by mouse
2424 {
2425 COLORREF TextColor, BackColor;
2426 int NoReverseColor = 2;
2427
2428 if (VTDC==NULL) DispInitDC();
2429
2430 if (TCharAttrCmp(DCAttr, Attr) == 0 && DCReverse == Reverse) {
2431 return;
2432 }
2433 DCAttr = Attr;
2434 DCReverse = Reverse;
2435
2436 SelectObject(VTDC, VTFont[Attr.Attr & AttrFontMask]);
2437
2438 if ((ts.ColorFlag & CF_FULLCOLOR) == 0) {
2439 if ((ts.ColorFlag & CF_BLINKCOLOR) && (Attr.Attr & AttrBlink)) {
2440 #ifdef ALPHABLEND_TYPE2 // AKASI
2441 TextColor = BGVTBlinkColor[0];
2442 BackColor = BGVTBlinkColor[1];
2443 #else
2444 TextColor = ts.VTBlinkColor[0];
2445 BackColor = ts.VTBlinkColor[1];
2446 #endif
2447 }
2448 else if ((ts.ColorFlag & CF_BOLDCOLOR) && (Attr.Attr & AttrBold)) {
2449 #ifdef ALPHABLEND_TYPE2 // AKASI
2450 TextColor = BGVTBoldColor[0];
2451 BackColor = BGVTBoldColor[1];
2452 #else
2453 TextColor = ts.VTBoldColor[0];
2454 BackColor = ts.VTBoldColor[1];
2455 #endif
2456 }
2457 /* begin - ishizaki */
2458 else if ((ts.ColorFlag & CF_URLCOLOR) && (Attr.Attr & AttrURL)) {
2459 #ifdef ALPHABLEND_TYPE2 // AKASI
2460 TextColor = BGURLColor[0];
2461 BackColor = BGURLColor[1];
2462 #else
2463 TextColor = ts.URLColor[0];
2464 BackColor = ts.URLColor[1];
2465 #endif
2466 }
2467 /* end - ishizaki */
2468 else {
2469 if ((ts.ColorFlag & CF_ANSICOLOR) && (Attr.Attr2 & Attr2Fore)) {
2470 TextColor = ANSIColor[Attr.Fore];
2471 }
2472 else {
2473 #ifdef ALPHABLEND_TYPE2 // AKASI
2474 TextColor = BGVTColor[0];
2475 #else
2476 TextColor = ts.VTColor[0];
2477 #endif
2478 NoReverseColor = 1;
2479 }
2480
2481 if ((ts.ColorFlag & CF_ANSICOLOR) && (Attr.Attr2 & Attr2Back)) {
2482 BackColor = ANSIColor[Attr.Back];
2483 }
2484 else {
2485 #ifdef ALPHABLEND_TYPE2 // AKASI
2486 BackColor = BGVTColor[1];
2487 #else
2488 BackColor = ts.VTColor[1];
2489 #endif
2490 if (NoReverseColor == 1) {
2491 NoReverseColor = !(ts.ColorFlag & CF_REVERSECOLOR);
2492 }
2493 }
2494 }
2495 }
2496 else { // full color
2497 if ((ts.ColorFlag & CF_ANSICOLOR) && (Attr.Attr2 & Attr2Fore)) {
2498 if (Attr.Fore<8 && (ts.ColorFlag&CF_PCBOLD16)) {
2499 if (((Attr.Attr&AttrBold)!=0) == (Attr.Fore!=0)) {
2500 TextColor = ANSIColor[Attr.Fore];
2501 }
2502 else {
2503 TextColor = ANSIColor[Attr.Fore ^ 8];
2504 }
2505 }
2506 else if (Attr.Fore < 16 && (Attr.Fore&7) != 0) {
2507 TextColor = ANSIColor[Attr.Fore ^ 8];
2508 }
2509 else {
2510 TextColor = ANSIColor[Attr.Fore];
2511 }
2512 }
2513 else if ((ts.ColorFlag & CF_BLINKCOLOR) && (Attr.Attr & AttrBlink))
2514 #ifdef ALPHABLEND_TYPE2 // AKASI
2515 TextColor = BGVTBlinkColor[0];
2516 else if ((ts.ColorFlag & CF_BOLDCOLOR) && (Attr.Attr & AttrBold))
2517 TextColor = BGVTBoldColor[0];
2518 else if ((ts.ColorFlag & CF_URLCOLOR) && (Attr.Attr & AttrURL))
2519 TextColor = BGURLColor[0];
2520 else {
2521 TextColor = BGVTColor[0];
2522 #else
2523 TextColor = ts.VTBlinkColor[0];
2524 else if ((ts.ColorFlag & CF_BOLDCOLOR) && (Attr.Attr & AttrBold))
2525 TextColor = ts.VTBoldColor[0];
2526 else if ((ts.ColorFlag & CF_URLCOLOR) && (Attr.Attr & AttrURL))
2527 TextColor = ts.URLColor[0];
2528 else {
2529 TextColor = ts.VTColor[0];
2530 #endif
2531 NoReverseColor = 1;
2532 }
2533 if ((ts.ColorFlag & CF_ANSICOLOR) && (Attr.Attr2 & Attr2Back)) {
2534 if (Attr.Back<8 && (ts.ColorFlag&CF_PCBOLD16)) {
2535 if (((Attr.Attr&AttrBlink)!=0) == (Attr.Back!=0)) {
2536 BackColor = ANSIColor[Attr.Back];
2537 }
2538 else {
2539 BackColor = ANSIColor[Attr.Back ^ 8];
2540 }
2541 }
2542 else if (Attr.Back < 16 && (Attr.Back&7) != 0) {
2543 BackColor = ANSIColor[Attr.Back ^ 8];
2544 }
2545 else {
2546 BackColor = ANSIColor[Attr.Back];
2547 }
2548 }
2549 else if ((ts.ColorFlag & CF_BLINKCOLOR) && (Attr.Attr & AttrBlink))
2550 #ifdef ALPHABLEND_TYPE2 // AKASI
2551 BackColor = BGVTBlinkColor[1];
2552 else if ((ts.ColorFlag & CF_BOLDCOLOR) && (Attr.Attr & AttrBold))
2553 BackColor = BGVTBoldColor[1];
2554 else if ((ts.ColorFlag & CF_URLCOLOR) && (Attr.Attr & AttrURL))
2555 BackColor = BGURLColor[1];
2556 else {
2557 BackColor = BGVTColor[1];
2558 #else
2559 BackColor = ts.VTBlinkColor[1];
2560 else if ((ts.ColorFlag & CF_BOLDCOLOR) && (Attr.Attr & AttrBold))
2561 BackColor = ts.VTBoldColor[1];
2562 else if ((ts.ColorFlag & CF_URLCOLOR) && (Attr.Attr & AttrURL))
2563 BackColor = ts.URLColor[1];
2564 else {
2565 BackColor = ts.VTColor[1];
2566 #endif
2567 if (NoReverseColor == 1) {
2568 NoReverseColor = !(ts.ColorFlag & CF_REVERSECOLOR);
2569 }
2570 }
2571 }
2572 #ifdef USE_NORMAL_BGCOLOR_REJECT
2573 if (ts.UseNormalBGColor) {
2574 #ifdef ALPHABLEND_TYPE2
2575 BackColor = BGVTColor[1];
2576 #else
2577 BackColor = ts.VTColor[1];
2578 #endif
2579 }
2580 #endif
2581
2582 if (Reverse != ((Attr.Attr & AttrReverse) != 0))
2583 {
2584 #ifdef ALPHABLEND_TYPE2
2585 BGReverseText = TRUE;
2586 #endif
2587 if ((Attr.Attr & AttrReverse) && !NoReverseColor) {
2588 #ifdef ALPHABLEND_TYPE2
2589 SetTextColor(VTDC, BGVTReverseColor[0]);
2590 SetBkColor( VTDC, BGVTReverseColor[1]);
2591 #else
2592 SetTextColor(VTDC, ts.VTReverseColor[0]);
2593 SetBkColor( VTDC, ts.VTReverseColor[1]);
2594 #endif
2595 }
2596 else {
2597 SetTextColor(VTDC, BackColor);
2598 SetBkColor( VTDC, TextColor);
2599 }
2600 }
2601 else {
2602 #ifdef ALPHABLEND_TYPE2 // by AKASI
2603 BGReverseText = FALSE;
2604 #endif
2605 SetTextColor(VTDC,TextColor);
2606 SetBkColor( VTDC,BackColor);
2607 }
2608 }
2609
2610 #if 1
2611 // ���������������������g���B(2004.11.4 yutaka)
2612 void DispStr(PCHAR Buff, int Count, int Y, int* X)
2613 // Display a string
2614 // Buff: points the string
2615 // Y: vertical position in window cordinate
2616 // *X: horizontal position
2617 // Return:
2618 // *X: horizontal position shifted by the width of the string
2619 {
2620 RECT RText;
2621
2622 if ((ts.Language==IdRussian) &&
2623 (ts.RussClient!=ts.RussFont))
2624 RussConvStr(ts.RussClient,ts.RussFont,Buff,Count);
2625
2626 RText.top = Y;
2627 RText.bottom = Y+FontHeight;
2628 RText.left = *X;
2629 RText.right = *X + Count*FontWidth;
2630
2631 #ifdef ALPHABLEND_TYPE2
2632 //<!--by AKASI
2633 if(!BGEnable)
2634 {
2635 ExtTextOut(VTDC,*X+ts.FontDX,Y+ts.FontDY,
2636 ETO_CLIPPED | ETO_OPAQUE,
2637 &RText,Buff,Count,&Dx[0]);
2638 }else{
2639
2640 int width;
2641 int height;
2642 int eto_options = ETO_CLIPPED;
2643 RECT rect;
2644 HFONT hPrevFont;
2645
2646 width = Count*FontWidth;
2647 height = FontHeight;
2648 SetRect(&rect,0,0,width,height);
2649
2650 //hdcBGBuffer ������������
2651 hPrevFont = SelectObject(hdcBGBuffer,GetCurrentObject(VTDC,OBJ_FONT));
2652 SetTextColor(hdcBGBuffer,GetTextColor(VTDC));
2653 SetBkColor(hdcBGBuffer,GetBkColor(VTDC));
2654
2655 //���������A���T�C�Y�����w�i�� BGBrushInSizeMove ���h��������
2656 if(BGInSizeMove)
2657 FillRect(hdcBGBuffer,&rect,BGBrushInSizeMove);
2658
2659 BitBlt(hdcBGBuffer,0,0,width,height,hdcBG,*X,Y,SRCCOPY);
2660
2661 if(BGReverseText == TRUE)
2662 {
2663 if(BGReverseTextAlpha < 255)
2664 {
2665 BGBLENDFUNCTION bf;
2666 HBRUSH hbr;
2667
2668 hbr = CreateSolidBrush(GetBkColor(hdcBGBuffer));
2669 FillRect(hdcBGWork,&rect,hbr);
2670 DeleteObject(hbr);
2671
2672 ZeroMemory(&bf,sizeof(bf));
2673 bf.BlendOp = AC_SRC_OVER;
2674 bf.SourceConstantAlpha = BGReverseTextAlpha;
2675
2676 BGAlphaBlend(hdcBGBuffer,0,0,width,height,hdcBGWork,0,0,width,height,bf);
2677 }else{
2678 eto_options |= ETO_OPAQUE;
2679 }
2680 }
2681
2682 ExtTextOut(hdcBGBuffer,ts.FontDX,ts.FontDY,eto_options,&rect,Buff,Count,&Dx[0]);
2683 BitBlt(VTDC,*X,Y,width,height,hdcBGBuffer,0,0,SRCCOPY);
2684
2685 SelectObject(hdcBGBuffer,hPrevFont);
2686 }
2687 //-->
2688 #else
2689 ExtTextOut(VTDC,*X+ts.FontDX,Y+ts.FontDY,
2690 ETO_CLIPPED | ETO_OPAQUE,
2691 &RText,Buff,Count,&Dx[0]);
2692 #endif
2693 *X = RText.right;
2694
2695 if ((ts.Language==IdRussian) &&
2696 (ts.RussClient!=ts.RussFont))
2697 RussConvStr(ts.RussFont,ts.RussClient,Buff,Count);
2698 }
2699
2700 #else
2701 void DispStr(PCHAR Buff, int Count, int Y, int* X)
2702 // Display a string
2703 // Buff: points the string
2704 // Y: vertical position in window cordinate
2705 // *X: horizontal position
2706 // Return:
2707 // *X: horizontal position shifted by the width of the string
2708 {
2709 RECT RText;
2710 wchar_t *wc;
2711 int len, wclen;
2712 CHAR ch;
2713
2714 #if 0
2715 #include <crtdbg.h>
2716 _CrtSetBreakAlloc(52);
2717 Buff[0] = 0x82;
2718 Buff[1] = 0xe4;
2719 Buff[2] = 0x82;
2720 Buff[3] = 0xbd;
2721 Buff[4] = 0x82;
2722 Buff[5] = 0xa9;
2723 Count = 6;
2724 #endif
2725
2726 setlocale(LC_ALL, ts.Locale);
2727
2728 ch = Buff[Count];
2729 Buff[Count] = 0;
2730 len = mbstowcs(NULL, Buff, 0);
2731
2732 wc = malloc(sizeof(wchar_t) * (len + 1));
2733 if (wc == NULL)
2734 return;
2735 wclen = mbstowcs(wc, Buff, len + 1);
2736 Buff[Count] = ch;
2737
2738 if ((ts.Language==IdRussian) &&
2739 (ts.RussClient!=ts.RussFont))
2740 RussConvStr(ts.RussClient,ts.RussFont,Buff,Count);
2741
2742 RText.top = Y;
2743 RText.bottom = Y+FontHeight;
2744 RText.left = *X;
2745 RText.right = *X + Count*FontWidth; //
2746
2747 // Unicode���o�������B
2748 #if 1
2749 // UTF-8�������������Atcsh��EUC�o�����������A�����������\���������������������B
2750 // �}�E�X���h���b�O�������A���O�t�@�C�������������������A��������������������
2751 // �m�F�����������������B(2004.8.6 yutaka)
2752 ExtTextOutW(VTDC,*X+ts.FontDX,Y+ts.FontDY,
2753 ETO_CLIPPED | ETO_OPAQUE,
2754 &RText, wc, wclen, NULL);
2755 // &RText, wc, wclen, &Dx[0]);
2756 #else
2757 TextOutW(VTDC, *X+ts.FontDX, Y+ts.FontDY, wc, wclen);
2758
2759 #endif
2760
2761 *X = RText.right;
2762
2763 if ((ts.Language==IdRussian) &&
2764 (ts.RussClient!=ts.RussFont))
2765 RussConvStr(ts.RussFont,ts.RussClient,Buff,Count);
2766
2767 free(wc);
2768 }
2769 #endif
2770
2771
2772 void DispEraseCurToEnd(int YEnd)
2773 {
2774 RECT R;
2775
2776 if (VTDC==NULL) DispInitDC();
2777 R.left = 0;
2778 R.right = ScreenWidth;
2779 R.top = (CursorY+1-WinOrgY)*FontHeight;
2780 R.bottom = (YEnd+1-WinOrgY)*FontHeight;
2781
2782 #ifdef ALPHABLEND_TYPE2
2783 //<!--by AKASI
2784 // FillRect(VTDC,&R,Background);
2785 BGFillRect(VTDC,&R,Background);
2786 //-->
2787 #else
2788 FillRect(VTDC,&R,Background);
2789 #endif
2790
2791 R.left = (CursorX-WinOrgX)*FontWidth;
2792 R.bottom = R.top;
2793 R.top = R.bottom-FontHeight;
2794
2795 #ifdef ALPHABLEND_TYPE2
2796 //<!--by AKASI
2797 // FillRect(VTDC,&R,Background);
2798 BGFillRect(VTDC,&R,Background);
2799 //-->
2800 #else
2801 FillRect(VTDC,&R,Background);
2802 #endif
2803 }
2804
2805 void DispEraseHomeToCur(int YHome)
2806 {
2807 RECT R;
2808
2809 if (VTDC==NULL) DispInitDC();
2810 R.left = 0;
2811 R.right = ScreenWidth;
2812 R.top = (YHome-WinOrgY)*FontHeight;
2813 R.bottom = (CursorY-WinOrgY)*FontHeight;
2814
2815 #ifdef ALPHABLEND_TYPE2
2816 //<!--by AKASI
2817 // FillRect(VTDC,&R,Background);
2818 BGFillRect(VTDC,&R,Background);
2819 //-->
2820 #else
2821 FillRect(VTDC,&R,Background);
2822 #endif
2823
2824 R.top = R.bottom;
2825 R.bottom = R.top + FontHeight;
2826 R.right = (CursorX+1-WinOrgX)*FontWidth;
2827
2828 #ifdef ALPHABLEND_TYPE2
2829 //<!--by AKASI
2830 // FillRect(VTDC,&R,Background);
2831 BGFillRect(VTDC,&R,Background);
2832 //-->
2833 #else
2834 FillRect(VTDC,&R,Background);
2835 #endif
2836 }
2837
2838 void DispEraseCharsInLine(int XStart, int Count)
2839 {
2840 RECT R;
2841
2842 if (VTDC==NULL) DispInitDC();
2843 R.top = (CursorY-WinOrgY)*FontHeight;
2844 R.bottom = R.top+FontHeight;
2845 R.left = (XStart-WinOrgX)*FontWidth;
2846 R.right = R.left + Count * FontWidth;
2847
2848 #ifdef ALPHABLEND_TYPE2
2849 //<!--by AKASI
2850 // FillRect(VTDC,&R,Background);
2851 BGFillRect(VTDC,&R,Background);
2852 //-->
2853 #else
2854 FillRect(VTDC,&R,Background);
2855 #endif
2856 }
2857
2858 BOOL DispDeleteLines(int Count, int YEnd)
2859 // return value:
2860 // TRUE - screen is successfully updated
2861 // FALSE - screen is not updated
2862 {
2863 RECT R;
2864
2865 if (Active && CompletelyVisible &&
2866 (YEnd+1-WinOrgY <= WinHeight))
2867 {
2868 R.left = 0;
2869 R.right = ScreenWidth;
2870 R.top = (CursorY-WinOrgY)*FontHeight;
2871 R.bottom = (YEnd+1-WinOrgY)*FontHeight;
2872 #ifdef ALPHABLEND_TYPE2
2873 //<!--by AKASI
2874 // ScrollWindow(HVTWin,0,-FontHeight*Count,&R,&R);
2875 BGScrollWindow(HVTWin,0,-FontHeight*Count,&R,&R);
2876 //-->
2877 #else
2878 ScrollWindow(HVTWin,0,-FontHeight*Count,&R,&R);
2879 #endif
2880 UpdateWindow(HVTWin);
2881 return TRUE;
2882 }
2883 else
2884 return FALSE;
2885 }
2886
2887 BOOL DispInsertLines(int Count, int YEnd)
2888 // return value:
2889 // TRUE - screen is successfully updated
2890 // FALSE - screen is not updated
2891 {
2892 RECT R;
2893
2894 if (Active && CompletelyVisible &&
2895 (CursorY >= WinOrgY))
2896 {
2897 R.left = 0;
2898 R.right = ScreenWidth;
2899 R.top = (CursorY-WinOrgY)*FontHeight;
2900 R.bottom = (YEnd+1-WinOrgY)*FontHeight;
2901 #ifdef ALPHABLEND_TYPE2
2902 //<!--by AKASI
2903 // ScrollWindow(HVTWin,0,FontHeight*Count,&R,&R);
2904 BGScrollWindow(HVTWin,0,FontHeight*Count,&R,&R);
2905 //-->
2906 #else
2907 ScrollWindow(HVTWin,0,FontHeight*Count,&R,&R);
2908 #endif
2909 UpdateWindow(HVTWin);
2910 return TRUE;
2911 }
2912 else
2913 return FALSE;
2914 }
2915
2916 BOOL IsLineVisible(int* X, int* Y)
2917 // Check the visibility of a line
2918 // called from UpdateStr()
2919 // *X, *Y: position of a character in the line. screen coord.
2920 // Return: TRUE if the line is visible.
2921 // *X, *Y:
2922 // If the line is visible
2923 // position of the character in window coord.
2924 // Otherwise
2925 // no change. same as input value.
2926 {
2927 if ((dScroll != 0) &&
2928 (*Y>=SRegionTop) &&
2929 (*Y<=SRegionBottom))
2930 {
2931 *Y = *Y + dScroll;
2932 if ((*Y<SRegionTop) || (*Y>SRegionBottom))
2933 return FALSE;
2934 }
2935
2936 if ((*Y<WinOrgY) ||
2937 (*Y>=WinOrgY+WinHeight))
2938 return FALSE;
2939
2940 /* screen coordinate -> window coordinate */
2941 *X = (*X-WinOrgX)*FontWidth;
2942 *Y = (*Y-WinOrgY)*FontHeight;
2943 return TRUE;
2944 }
2945
2946 //-------------- scrolling functions --------------------
2947
2948 void AdjustScrollBar() /* called by ChangeWindowSize() */
2949 {
2950 LONG XRange, YRange;
2951 int ScrollPosX, ScrollPosY;
2952
2953 if (NumOfColumns-WinWidth>0)
2954 XRange = NumOfColumns-WinWidth;
2955 else
2956 XRange = 0;
2957
2958 if (BuffEnd-WinHeight>0)
2959 YRange = BuffEnd-WinHeight;
2960 else
2961 YRange = 0;
2962
2963 ScrollPosX = GetScrollPos(HVTWin,SB_HORZ);
2964 ScrollPosY = GetScrollPos(HVTWin,SB_VERT);
2965 if (ScrollPosX > XRange)
2966 ScrollPosX = XRange;
2967 if (ScrollPosY > YRange)
2968 ScrollPosY = YRange;
2969
2970 WinOrgX = ScrollPosX;
2971 WinOrgY = ScrollPosY-PageStart;
2972 NewOrgX = WinOrgX;
2973 NewOrgY = WinOrgY;
2974
2975 DontChangeSize = TRUE;
2976
2977 SetScrollRange(HVTWin,SB_HORZ,0,XRange,FALSE);
2978
2979 if ((YRange == 0) && (ts.EnableScrollBuff>0))
2980 {
2981 SetScrollRange(HVTWin,SB_VERT,0,1,FALSE);
2982 }
2983 else {
2984 SetScrollRange(HVTWin,SB_VERT,0,YRange,FALSE);
2985 }
2986
2987 SetScrollPos(HVTWin,SB_HORZ,ScrollPosX,TRUE);
2988 SetScrollPos(HVTWin,SB_VERT,ScrollPosY,TRUE);
2989
2990 DontChangeSize = FALSE;
2991 }
2992
2993 void DispScrollToCursor(int CurX, int CurY)
2994 {
2995 if (CurX < NewOrgX)
2996 NewOrgX = CurX;
2997 else if (CurX >= NewOrgX+WinWidth)
2998 NewOrgX = CurX + 1 - WinWidth;
2999
3000 if (CurY < NewOrgY)
3001 NewOrgY = CurY;
3002 else if (CurY >= NewOrgY+WinHeight)
3003 NewOrgY = CurY + 1 - WinHeight;
3004 }
3005
3006 void DispScrollNLines(int Top, int Bottom, int Direction)
3007 // Scroll a region of the window by Direction lines
3008 // updates window if necessary
3009 // Top: top line of scroll region
3010 // Bottom: bottom line
3011 // Direction: +: forward, -: backward
3012 {
3013 if ((dScroll*Direction <0) ||
3014 (dScroll*Direction >0) &&
3015 ((SRegionTop!=Top) ||
3016 (SRegionBottom!=Bottom)))
3017 DispUpdateScroll();
3018 SRegionTop = Top;
3019 SRegionBottom