Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /branches/ttcomtester/teraterm/teraterm/buffer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5089 - (hide annotations) (download) (as text)
Tue Dec 4 00:54:13 2012 UTC (11 years, 4 months ago) by doda
Original Path: trunk/teraterm/teraterm/buffer.c
File MIME type: text/x-csrc
File size: 90636 byte(s)
DECCRAに仮対応

1 maya 3227 /* Tera Term
2     Copyright(C) 1994-1998 T. Teranishi
3     All rights reserved. */
4    
5     /* TERATERM.EXE, scroll buffer routines */
6    
7     #include "teraterm.h"
8     #include "tttypes.h"
9     #include <string.h>
10 yutakapon 4707 #include <stdio.h>
11 maya 3227
12     #include "ttwinman.h"
13     #include "teraprn.h"
14     #include "vtdisp.h"
15     #include "clipboar.h"
16     #include "telnet.h"
17     #include "ttplug.h" /* TTPLUG */
18    
19     #include "buffer.h"
20    
21     // URLを強調する(石崎氏パッチ 2005/4/2)
22     #define URL_EMPHASIS 1
23    
24     #define BuffXMax TermWidthMax
25     //#define BuffYMax 100000
26     //#define BuffSizeMax 8000000
27     // スクロールバッファの最大長を拡張 (2004.11.28 yutaka)
28     #define BuffYMax 500000
29     #define BuffSizeMax (BuffYMax * 80)
30    
31     // status line
32     int StatusLine; //0: none 1: shown
33     /* top & bottom margin */
34     int CursorTop, CursorBottom;
35     BOOL Selected;
36     BOOL Wrap;
37    
38     static WORD TabStops[256];
39     static int NTabStops;
40    
41     static WORD BuffLock = 0;
42     static HANDLE HCodeBuff = 0;
43     static HANDLE HAttrBuff = 0;
44     static HANDLE HAttrBuff2 = 0;
45     static HANDLE HAttrBuffFG = 0;
46     static HANDLE HAttrBuffBG = 0;
47    
48     static PCHAR CodeBuff; /* Character code buffer */
49     static PCHAR AttrBuff; /* Attribute buffer */
50     static PCHAR AttrBuff2; /* Color attr buffer */
51     static PCHAR AttrBuffFG; /* Foreground color attr buffer */
52     static PCHAR AttrBuffBG; /* Background color attr buffer */
53     static PCHAR CodeLine;
54     static PCHAR AttrLine;
55     static PCHAR AttrLine2;
56     static PCHAR AttrLineFG;
57     static PCHAR AttrLineBG;
58     static LONG LinePtr;
59     static LONG BufferSize;
60     static int NumOfLinesInBuff;
61     static int BuffStartAbs, BuffEndAbs;
62     static POINT SelectStart, SelectEnd, SelectEndOld;
63     static BOOL BoxSelect;
64     static POINT DblClkStart, DblClkEnd;
65    
66     static int StrChangeStart, StrChangeCount;
67    
68     static BOOL SeveralPageSelect; // add (2005.5.15 yutaka)
69    
70     static TCharAttr CurCharAttr;
71    
72 doda 3743 HANDLE SaveBuff = NULL;
73     int SaveBuffX;
74     int SaveBuffY;
75    
76 maya 3227 LONG GetLinePtr(int Line)
77     {
78 maya 3393 LONG Ptr;
79 maya 3227
80 maya 3393 Ptr = (LONG)(BuffStartAbs + Line) * (LONG)(NumOfColumns);
81     while (Ptr>=BufferSize) {
82     Ptr = Ptr - BufferSize;
83     }
84     return Ptr;
85 maya 3227 }
86    
87     LONG NextLinePtr(LONG Ptr)
88     {
89 maya 3393 Ptr = Ptr + (LONG)NumOfColumns;
90     if (Ptr >= BufferSize) {
91     Ptr = Ptr - BufferSize;
92     }
93     return Ptr;
94 maya 3227 }
95    
96     LONG PrevLinePtr(LONG Ptr)
97     {
98 maya 3393 Ptr = Ptr - (LONG)NumOfColumns;
99     if (Ptr < 0) {
100     Ptr = Ptr + BufferSize;
101     }
102     return Ptr;
103 maya 3227 }
104    
105     BOOL ChangeBuffer(int Nx, int Ny)
106     {
107 maya 3393 HANDLE HCodeNew, HAttrNew, HAttr2New, HAttrFGNew, HAttrBGNew;
108     LONG NewSize;
109     int NxCopy, NyCopy, i;
110     PCHAR CodeDest, AttrDest, AttrDest2, AttrDestFG, AttrDestBG;
111     LONG SrcPtr, DestPtr;
112     WORD LockOld;
113 maya 3227
114 maya 3393 if (Nx > BuffXMax) {
115     Nx = BuffXMax;
116     }
117     if (ts.ScrollBuffMax > BuffYMax) {
118     ts.ScrollBuffMax = BuffYMax;
119     }
120     if (Ny > ts.ScrollBuffMax) {
121     Ny = ts.ScrollBuffMax;
122     }
123 maya 3227
124 maya 3393 if ( (LONG)Nx * (LONG)Ny > BuffSizeMax ) {
125     Ny = BuffSizeMax / Nx;
126     }
127 maya 3227
128 maya 3393 NewSize = (LONG)Nx * (LONG)Ny;
129 maya 3227
130 doda 3686 HCodeNew = NULL;
131     HAttrNew = NULL;
132     HAttr2New = NULL;
133     HAttrFGNew = NULL;
134     HAttrBGNew = NULL;
135 maya 3227
136 doda 3686 if ((HCodeNew=GlobalAlloc(GMEM_MOVEABLE, NewSize)) == NULL || (CodeDest=GlobalLock(HCodeNew)) == NULL) {
137     goto allocate_error;
138 maya 3393 }
139 doda 3686 if ((HAttrNew=GlobalAlloc(GMEM_MOVEABLE, NewSize)) == NULL || (AttrDest=GlobalLock(HAttrNew)) == NULL) {
140     goto allocate_error;
141 maya 3393 }
142 doda 3686 if ((HAttr2New=GlobalAlloc(GMEM_MOVEABLE, NewSize)) == NULL || (AttrDest2=GlobalLock(HAttr2New)) == NULL) {
143     goto allocate_error;
144 maya 3393 }
145 doda 3686 if ((HAttrFGNew=GlobalAlloc(GMEM_MOVEABLE, NewSize)) == NULL || (AttrDestFG=GlobalLock(HAttrFGNew)) == NULL) {
146     goto allocate_error;
147 maya 3393 }
148 doda 3686 if ((HAttrBGNew=GlobalAlloc(GMEM_MOVEABLE, NewSize)) == NULL || (AttrDestBG=GlobalLock(HAttrBGNew)) == NULL) {
149     goto allocate_error;
150 maya 3393 }
151 maya 3227
152 maya 3393 memset(&CodeDest[0], 0x20, NewSize);
153     memset(&AttrDest[0], AttrDefault, NewSize);
154     memset(&AttrDest2[0], AttrDefault, NewSize);
155     memset(&AttrDestFG[0], AttrDefaultFG, NewSize);
156     memset(&AttrDestBG[0], AttrDefaultBG, NewSize);
157     if ( HCodeBuff!=0 ) {
158     if ( NumOfColumns > Nx ) {
159     NxCopy = Nx;
160     }
161     else {
162     NxCopy = NumOfColumns;
163     }
164 maya 3227
165 maya 3393 if ( BuffEnd > Ny ) {
166     NyCopy = Ny;
167     }
168     else {
169     NyCopy = BuffEnd;
170     }
171     LockOld = BuffLock;
172     LockBuffer();
173     SrcPtr = GetLinePtr(BuffEnd-NyCopy);
174     DestPtr = 0;
175     for (i = 1 ; i <= NyCopy ; i++) {
176     memcpy(&CodeDest[DestPtr],&CodeBuff[SrcPtr],NxCopy);
177     memcpy(&AttrDest[DestPtr],&AttrBuff[SrcPtr],NxCopy);
178     memcpy(&AttrDest2[DestPtr],&AttrBuff2[SrcPtr],NxCopy);
179     memcpy(&AttrDestFG[DestPtr],&AttrBuffFG[SrcPtr],NxCopy);
180     memcpy(&AttrDestBG[DestPtr],&AttrBuffBG[SrcPtr],NxCopy);
181 doda 3766 if (AttrDest[DestPtr+NxCopy-1] & AttrKanji) {
182     CodeDest[DestPtr+NxCopy-1] = ' ';
183     AttrDest[DestPtr+NxCopy-1] ^= AttrKanji;
184     }
185 maya 3393 SrcPtr = NextLinePtr(SrcPtr);
186     DestPtr = DestPtr + (LONG)Nx;
187     }
188     FreeBuffer();
189     }
190     else {
191     LockOld = 0;
192     NyCopy = NumOfLines;
193     Selected = FALSE;
194     }
195 maya 3227
196 maya 3393 if (Selected) {
197     SelectStart.y = SelectStart.y - BuffEnd + NyCopy;
198     SelectEnd.y = SelectEnd.y - BuffEnd + NyCopy;
199     if (SelectStart.y < 0) {
200     SelectStart.y = 0;
201     SelectStart.x = 0;
202     }
203     if (SelectEnd.y<0) {
204     SelectEnd.x = 0;
205     SelectEnd.y = 0;
206     }
207 maya 3227
208 maya 3393 Selected = (SelectEnd.y > SelectStart.y) ||
209     ((SelectEnd.y=SelectStart.y) &&
210     (SelectEnd.x > SelectStart.x));
211     }
212 maya 3227
213 maya 3393 HCodeBuff = HCodeNew;
214     HAttrBuff = HAttrNew;
215     HAttrBuff2 = HAttr2New;
216     HAttrBuffFG = HAttrFGNew;
217     HAttrBuffBG = HAttrBGNew;
218     BufferSize = NewSize;
219     NumOfLinesInBuff = Ny;
220     BuffStartAbs = 0;
221     BuffEnd = NyCopy;
222 maya 3227
223 maya 3393 if (BuffEnd==NumOfLinesInBuff) {
224     BuffEndAbs = 0;
225     }
226     else {
227     BuffEndAbs = BuffEnd;
228     }
229 maya 3227
230 maya 3393 PageStart = BuffEnd - NumOfLines;
231    
232     LinePtr = 0;
233     if (LockOld>0) {
234     CodeBuff = (PCHAR)GlobalLock(HCodeBuff);
235     AttrBuff = (PCHAR)GlobalLock(HAttrBuff);
236     AttrBuff2 = (PCHAR)GlobalLock(HAttrBuff2);
237     AttrBuffFG = (PCHAR)GlobalLock(HAttrBuffFG);
238     AttrBuffBG = (PCHAR)GlobalLock(HAttrBuffBG);
239     CodeLine = CodeBuff;
240     AttrLine = AttrBuff;
241     AttrLine2 = AttrBuff2;
242     AttrLineFG = AttrBuffFG;
243     AttrLineBG = AttrBuffBG;
244     }
245     else {
246     GlobalUnlock(HCodeNew);
247     GlobalUnlock(HAttrNew);
248 doda 3621 GlobalUnlock(HAttr2New);
249     GlobalUnlock(HAttrFGNew);
250     GlobalUnlock(HAttrBGNew);
251 maya 3393 }
252     BuffLock = LockOld;
253    
254     return TRUE;
255 doda 3686
256     allocate_error:
257     if (CodeDest) GlobalUnlock(HCodeNew);
258     if (AttrDest) GlobalUnlock(HAttrNew);
259     if (AttrDest2) GlobalUnlock(HAttr2New);
260     if (AttrDestFG) GlobalUnlock(HAttrFGNew);
261     if (AttrDestBG) GlobalUnlock(HAttrBGNew);
262     if (HCodeNew) GlobalFree(HCodeNew);
263     if (HAttrNew) GlobalFree(HAttrNew);
264     if (HAttr2New) GlobalFree(HAttr2New);
265     if (HAttrFGNew) GlobalFree(HAttrFGNew);
266     if (HAttrBGNew) GlobalFree(HAttrBGNew);
267     return FALSE;
268 maya 3227 }
269    
270     void InitBuffer()
271     {
272 maya 3393 int Ny;
273 maya 3227
274 maya 3393 /* setup terminal */
275     NumOfColumns = ts.TerminalWidth;
276     NumOfLines = ts.TerminalHeight;
277 maya 3227
278 maya 3393 /* setup window */
279     if (ts.EnableScrollBuff>0) {
280     if (ts.ScrollBuffSize < NumOfLines) {
281     ts.ScrollBuffSize = NumOfLines;
282     }
283     Ny = ts.ScrollBuffSize;
284     }
285     else {
286     Ny = NumOfLines;
287     }
288 maya 3227
289 maya 3393 if (! ChangeBuffer(NumOfColumns,Ny)) {
290     PostQuitMessage(0);
291     }
292 maya 3227
293 maya 3393 if (ts.EnableScrollBuff>0) {
294     ts.ScrollBuffSize = NumOfLinesInBuff;
295     }
296 maya 3227
297 maya 3393 StatusLine = 0;
298 maya 3227 }
299    
300     void NewLine(int Line)
301     {
302 maya 3393 LinePtr = GetLinePtr(Line);
303     CodeLine = &CodeBuff[LinePtr];
304     AttrLine = &AttrBuff[LinePtr];
305     AttrLine2 = &AttrBuff2[LinePtr];
306     AttrLineFG = &AttrBuffFG[LinePtr];
307     AttrLineBG = &AttrBuffBG[LinePtr];
308 maya 3227 }
309    
310     void LockBuffer()
311     {
312 maya 3393 BuffLock++;
313     if (BuffLock>1) {
314     return;
315     }
316     CodeBuff = (PCHAR)GlobalLock(HCodeBuff);
317     AttrBuff = (PCHAR)GlobalLock(HAttrBuff);
318     AttrBuff2 = (PCHAR)GlobalLock(HAttrBuff2);
319     AttrBuffFG = (PCHAR)GlobalLock(HAttrBuffFG);
320     AttrBuffBG = (PCHAR)GlobalLock(HAttrBuffBG);
321     NewLine(PageStart+CursorY);
322 maya 3227 }
323    
324     void UnlockBuffer()
325     {
326 maya 3393 if (BuffLock==0) {
327     return;
328     }
329     BuffLock--;
330     if (BuffLock>0) {
331     return;
332     }
333     if (HCodeBuff!=NULL) {
334     GlobalUnlock(HCodeBuff);
335     }
336     if (HAttrBuff!=NULL) {
337     GlobalUnlock(HAttrBuff);
338     }
339     if (HAttrBuff2!=NULL) {
340     GlobalUnlock(HAttrBuff2);
341     }
342     if (HAttrBuffFG!=NULL) {
343     GlobalUnlock(HAttrBuffFG);
344     }
345     if (HAttrBuffBG!=NULL) {
346     GlobalUnlock(HAttrBuffBG);
347     }
348 maya 3227 }
349    
350     void FreeBuffer()
351     {
352 maya 3393 BuffLock = 1;
353     UnlockBuffer();
354     if (HCodeBuff!=NULL) {
355     GlobalFree(HCodeBuff);
356     HCodeBuff = NULL;
357     }
358     if (HAttrBuff!=NULL) {
359     GlobalFree(HAttrBuff);
360     HAttrBuff = NULL;
361     }
362     if (HAttrBuff2!=NULL) {
363     GlobalFree(HAttrBuff2);
364     HAttrBuff2 = NULL;
365     }
366     if (HAttrBuffFG!=NULL) {
367     GlobalFree(HAttrBuffFG);
368     HAttrBuffFG = NULL;
369     }
370     if (HAttrBuffBG!=NULL) {
371     GlobalFree(HAttrBuffBG);
372     HAttrBuffBG = NULL;
373     }
374 maya 3227 }
375    
376     void BuffAllSelect()
377     {
378     SelectStart.x = 0;
379     SelectStart.y = 0;
380     SelectEnd.x = 0;
381     SelectEnd.y = BuffEnd;
382     // SelectEnd.x = NumOfColumns;
383     // SelectEnd.y = BuffEnd - 1;
384     }
385    
386     void BuffScreenSelect()
387     {
388     int X, Y;
389     DispConvWinToScreen(0, 0, &X, &Y, NULL);
390     SelectStart.x = X;
391     SelectStart.y = Y + PageStart;
392     SelectEnd.x = 0;
393     SelectEnd.y = SelectStart.y + NumOfLines;
394     // SelectEnd.x = X + NumOfColumns;
395     // SelectEnd.y = Y + PageStart + NumOfLines - 1;
396     }
397    
398     void BuffCancelSelection()
399     {
400     SelectStart.x = 0;
401     SelectStart.y = 0;
402     SelectEnd.x = 0;
403     SelectEnd.y = 0;
404     }
405    
406     void BuffReset()
407     // Reset buffer status. don't update real display
408     // called by ResetTerminal()
409     {
410 maya 3393 int i;
411 maya 3227
412 maya 3393 /* Cursor */
413     NewLine(PageStart);
414     WinOrgX = 0;
415     WinOrgY = 0;
416     NewOrgX = 0;
417     NewOrgY = 0;
418 maya 3227
419 maya 3393 /* Top/bottom margin */
420     CursorTop = 0;
421     CursorBottom = NumOfLines-1;
422 maya 3227
423 maya 3393 /* Tab stops */
424     NTabStops = (NumOfColumns-1) >> 3;
425     for (i=1 ; i<=NTabStops ; i++) {
426     TabStops[i-1] = i*8;
427     }
428 maya 3227
429 maya 3393 /* Initialize text selection region */
430     SelectStart.x = 0;
431     SelectStart.y = 0;
432     SelectEnd = SelectStart;
433     SelectEndOld = SelectStart;
434     Selected = FALSE;
435 maya 3227
436 maya 3393 StrChangeCount = 0;
437     Wrap = FALSE;
438     StatusLine = 0;
439 maya 3227
440 maya 3393 SeveralPageSelect = FALSE; // yutaka
441 doda 3745
442     /* Alternate Screen Buffer */
443     BuffDiscardSavedScreen();
444 maya 3227 }
445    
446     void BuffScroll(int Count, int Bottom)
447     {
448 maya 3393 int i, n;
449     LONG SrcPtr, DestPtr;
450     int BuffEndOld;
451 maya 3227
452 maya 3393 if (Count>NumOfLinesInBuff) {
453     Count = NumOfLinesInBuff;
454     }
455 maya 3227
456 maya 3393 DestPtr = GetLinePtr(PageStart+NumOfLines-1+Count);
457     n = Count;
458     if (Bottom<NumOfLines-1) {
459     SrcPtr = GetLinePtr(PageStart+NumOfLines-1);
460     for (i=NumOfLines-1; i>=Bottom+1; i--) {
461     memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
462     memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
463     memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
464     memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
465     memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
466     memset(&(CodeBuff[SrcPtr]),0x20,NumOfColumns);
467     memset(&(AttrBuff[SrcPtr]),AttrDefault,NumOfColumns);
468 doda 4070 memset(&(AttrBuff2[SrcPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
469 maya 3393 memset(&(AttrBuffFG[SrcPtr]),CurCharAttr.Fore,NumOfColumns);
470     memset(&(AttrBuffBG[SrcPtr]),CurCharAttr.Back,NumOfColumns);
471     SrcPtr = PrevLinePtr(SrcPtr);
472     DestPtr = PrevLinePtr(DestPtr);
473     n--;
474     }
475     }
476     for (i = 1 ; i <= n ; i++) {
477     memset(&CodeBuff[DestPtr],0x20,NumOfColumns);
478     memset(&AttrBuff[DestPtr],AttrDefault,NumOfColumns);
479 doda 4070 memset(&AttrBuff2[DestPtr],CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
480 maya 3393 memset(&AttrBuffFG[DestPtr],CurCharAttr.Fore,NumOfColumns);
481     memset(&AttrBuffBG[DestPtr],CurCharAttr.Back,NumOfColumns);
482     DestPtr = PrevLinePtr(DestPtr);
483     }
484 maya 3227
485 maya 3393 BuffEndAbs = BuffEndAbs + Count;
486     if (BuffEndAbs >= NumOfLinesInBuff) {
487     BuffEndAbs = BuffEndAbs - NumOfLinesInBuff;
488     }
489     BuffEndOld = BuffEnd;
490     BuffEnd = BuffEnd + Count;
491     if (BuffEnd >= NumOfLinesInBuff) {
492     BuffEnd = NumOfLinesInBuff;
493     BuffStartAbs = BuffEndAbs;
494     }
495     PageStart = BuffEnd-NumOfLines;
496 maya 3227
497 maya 3393 if (Selected) {
498     SelectStart.y = SelectStart.y - Count + BuffEnd - BuffEndOld;
499     SelectEnd.y = SelectEnd.y - Count + BuffEnd - BuffEndOld;
500     if ( SelectStart.y<0 ) {
501     SelectStart.x = 0;
502     SelectStart.y = 0;
503     }
504     if ( SelectEnd.y<0 ) {
505     SelectEnd.x = 0;
506     SelectEnd.y = 0;
507     }
508     Selected = (SelectEnd.y > SelectStart.y) ||
509     ((SelectEnd.y==SelectStart.y) &&
510     (SelectEnd.x > SelectStart.x));
511     }
512 maya 3227
513 maya 3393 NewLine(PageStart+CursorY);
514 maya 3227 }
515    
516     void NextLine()
517     {
518 maya 3393 LinePtr = NextLinePtr(LinePtr);
519     CodeLine = &CodeBuff[LinePtr];
520     AttrLine = &AttrBuff[LinePtr];
521     AttrLine2 = &AttrBuff2[LinePtr];
522     AttrLineFG = &AttrBuffFG[LinePtr];
523     AttrLineBG = &AttrBuffBG[LinePtr];
524 maya 3227 }
525    
526     void PrevLine()
527     {
528 maya 3393 LinePtr = PrevLinePtr(LinePtr);
529     CodeLine = &CodeBuff[LinePtr];
530     AttrLine = &AttrBuff[LinePtr];
531     AttrLine2 = &AttrBuff2[LinePtr];
532     AttrLineFG = &AttrBuffFG[LinePtr];
533     AttrLineBG = &AttrBuffBG[LinePtr];
534 maya 3227 }
535    
536     void EraseKanji(int LR)
537     {
538     // If cursor is on left/right half of a Kanji, erase it.
539     // LR: left(0)/right(1) flag
540    
541 maya 3393 if ((CursorX-LR>=0) &&
542     ((AttrLine[CursorX-LR] & AttrKanji) != 0)) {
543     CodeLine[CursorX-LR] = 0x20;
544     AttrLine[CursorX-LR] = CurCharAttr.Attr;
545     AttrLine2[CursorX-LR] = CurCharAttr.Attr2;
546     AttrLineFG[CursorX-LR] = CurCharAttr.Fore;
547     AttrLineBG[CursorX-LR] = CurCharAttr.Back;
548     if (CursorX-LR+1 < NumOfColumns) {
549     CodeLine[CursorX-LR+1] = 0x20;
550     AttrLine[CursorX-LR+1] = CurCharAttr.Attr;
551     AttrLine2[CursorX-LR+1] = CurCharAttr.Attr2;
552     AttrLineFG[CursorX-LR+1] = CurCharAttr.Fore;
553     AttrLineBG[CursorX-LR+1] = CurCharAttr.Back;
554     }
555     }
556 maya 3227 }
557    
558     void BuffInsertSpace(int Count)
559     // Insert space characters at the current position
560     // Count: Number of characters to be inserted
561     {
562 maya 3393 NewLine(PageStart+CursorY);
563 maya 3227
564 doda 3416 if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
565 maya 3393 EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
566     }
567 maya 3227
568 maya 3393 if (Count > NumOfColumns - CursorX) {
569     Count = NumOfColumns - CursorX;
570     }
571 maya 3227
572 maya 3393 memmove(&(CodeLine[CursorX+Count]),&(CodeLine[CursorX]),
573     NumOfColumns-Count-CursorX);
574     memmove(&(AttrLine[CursorX+Count]),&(AttrLine[CursorX]),
575     NumOfColumns-Count-CursorX);
576     memmove(&(AttrLine2[CursorX+Count]),&(AttrLine2[CursorX]),
577     NumOfColumns-Count-CursorX);
578     memmove(&(AttrLineFG[CursorX+Count]),&(AttrLineFG[CursorX]),
579     NumOfColumns-Count-CursorX);
580     memmove(&(AttrLineBG[CursorX+Count]),&(AttrLineBG[CursorX]),
581     NumOfColumns-Count-CursorX);
582     memset(&(CodeLine[CursorX]),0x20,Count);
583     memset(&(AttrLine[CursorX]),AttrDefault,Count);
584 doda 4070 memset(&(AttrLine2[CursorX]),CurCharAttr.Attr2 & Attr2ColorMask, Count);
585 maya 3393 memset(&(AttrLineFG[CursorX]),CurCharAttr.Fore,Count);
586     memset(&(AttrLineBG[CursorX]),CurCharAttr.Back,Count);
587     /* last char in current line is kanji first? */
588     if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0) {
589     /* then delete it */
590     CodeLine[NumOfColumns-1] = 0x20;
591     AttrLine[NumOfColumns-1] = AttrDefault;
592     AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
593     AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
594     AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
595     }
596     BuffUpdateRect(CursorX,CursorY,NumOfColumns-1,CursorY);
597 maya 3227 }
598    
599     void BuffEraseCurToEnd()
600     // Erase characters from cursor to the end of screen
601     {
602 maya 3393 LONG TmpPtr;
603     int offset;
604     int i, YEnd;
605 maya 3227
606 maya 3393 NewLine(PageStart+CursorY);
607 doda 3416 if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
608 maya 3393 EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
609     }
610     offset = CursorX;
611     TmpPtr = GetLinePtr(PageStart+CursorY);
612     YEnd = NumOfLines-1;
613     if ((StatusLine>0) &&
614     (CursorY<NumOfLines-1)) {
615     YEnd--;
616     }
617     for (i = CursorY ; i <= YEnd ; i++) {
618     memset(&(CodeBuff[TmpPtr+offset]),0x20,NumOfColumns-offset);
619     memset(&(AttrBuff[TmpPtr+offset]),AttrDefault,NumOfColumns-offset);
620 doda 4070 memset(&(AttrBuff2[TmpPtr+offset]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns-offset);
621 maya 3393 memset(&(AttrBuffFG[TmpPtr+offset]),CurCharAttr.Fore,NumOfColumns-offset);
622     memset(&(AttrBuffBG[TmpPtr+offset]),CurCharAttr.Back,NumOfColumns-offset);
623     offset = 0;
624     TmpPtr = NextLinePtr(TmpPtr);
625     }
626     /* update window */
627     DispEraseCurToEnd(YEnd);
628 maya 3227 }
629    
630     void BuffEraseHomeToCur()
631     // Erase characters from home to cursor
632     {
633 maya 3393 LONG TmpPtr;
634     int offset;
635     int i, YHome;
636 maya 3227
637 maya 3393 NewLine(PageStart+CursorY);
638 doda 3416 if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
639 maya 3393 EraseKanji(0); /* if cursor is on left half of a kanji, erase the kanji */
640     }
641     offset = NumOfColumns;
642     if ((StatusLine>0) && (CursorY==NumOfLines-1)) {
643     YHome = CursorY;
644     }
645     else {
646     YHome = 0;
647     }
648     TmpPtr = GetLinePtr(PageStart+YHome);
649     for (i = YHome ; i <= CursorY ; i++) {
650     if (i==CursorY) {
651     offset = CursorX+1;
652     }
653     memset(&(CodeBuff[TmpPtr]),0x20,offset);
654     memset(&(AttrBuff[TmpPtr]),AttrDefault,offset);
655 doda 4070 memset(&(AttrBuff2[TmpPtr]),CurCharAttr.Attr2 & Attr2ColorMask, offset);
656 maya 3393 memset(&(AttrBuffFG[TmpPtr]),CurCharAttr.Fore,offset);
657     memset(&(AttrBuffBG[TmpPtr]),CurCharAttr.Back,offset);
658     TmpPtr = NextLinePtr(TmpPtr);
659     }
660 maya 3227
661 maya 3393 /* update window */
662     DispEraseHomeToCur(YHome);
663 maya 3227 }
664    
665     void BuffInsertLines(int Count, int YEnd)
666     // Insert lines at current position
667     // Count: number of lines to be inserted
668     // YEnd: bottom line number of scroll region (screen coordinate)
669     {
670 maya 3393 int i;
671     LONG SrcPtr, DestPtr;
672 maya 3227
673 maya 3393 BuffUpdateScroll();
674 maya 3227
675 maya 3393 SrcPtr = GetLinePtr(PageStart+YEnd-Count);
676     DestPtr = GetLinePtr(PageStart+YEnd);
677     for (i= YEnd-Count ; i>=CursorY ; i--) {
678     memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
679     memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
680     memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
681     memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
682     memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
683     SrcPtr = PrevLinePtr(SrcPtr);
684     DestPtr = PrevLinePtr(DestPtr);
685     }
686     for (i = 1 ; i <= Count ; i++) {
687     memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
688     memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
689 doda 4070 memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
690 maya 3393 memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
691     memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
692     DestPtr = PrevLinePtr(DestPtr);
693     }
694 maya 3227
695 maya 3393 if (! DispInsertLines(Count,YEnd)) {
696     BuffUpdateRect(WinOrgX,CursorY,WinOrgX+WinWidth-1,YEnd);
697     }
698 maya 3227 }
699    
700     void BuffEraseCharsInLine(int XStart, int Count)
701     // erase characters in the current line
702     // XStart: start position of erasing
703     // Count: number of characters to be erased
704     {
705 doda 3312 #ifndef NO_COPYLINE_FIX
706 maya 3393 BOOL LineContinued=FALSE;
707 doda 3312
708 maya 3393 if (ts.EnableContinuedLineCopy && XStart == 0 && (AttrLine[0] & AttrLineContinued)) {
709     LineContinued = TRUE;
710     }
711 doda 3312 #endif /* NO_COPYLINE_FIX */
712    
713 doda 3416 if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
714 maya 3393 EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
715     }
716 maya 3227
717 maya 3393 NewLine(PageStart+CursorY);
718     memset(&(CodeLine[XStart]),0x20,Count);
719     memset(&(AttrLine[XStart]),AttrDefault,Count);
720 doda 4070 memset(&(AttrLine2[XStart]),CurCharAttr.Attr2 & Attr2ColorMask, Count);
721 maya 3393 memset(&(AttrLineFG[XStart]),CurCharAttr.Fore,Count);
722     memset(&(AttrLineBG[XStart]),CurCharAttr.Back,Count);
723 maya 3227
724 doda 3312 #ifndef NO_COPYLINE_FIX
725 maya 3393 if (ts.EnableContinuedLineCopy) {
726     if (LineContinued) {
727     BuffLineContinued(TRUE);
728     }
729    
730     if (XStart + Count >= NumOfColumns) {
731     AttrBuff[NextLinePtr(LinePtr)] &= ~AttrLineContinued;
732     }
733     }
734 doda 3312 #endif /* NO_COPYLINE_FIX */
735    
736 maya 3393 DispEraseCharsInLine(XStart, Count);
737 maya 3227 }
738    
739     void BuffDeleteLines(int Count, int YEnd)
740     // Delete lines from current line
741     // Count: number of lines to be deleted
742     // YEnd: bottom line number of scroll region (screen coordinate)
743     {
744 maya 3393 int i;
745     LONG SrcPtr, DestPtr;
746 maya 3227
747 maya 3393 BuffUpdateScroll();
748 maya 3227
749 maya 3393 SrcPtr = GetLinePtr(PageStart+CursorY+Count);
750     DestPtr = GetLinePtr(PageStart+CursorY);
751     for (i=CursorY ; i<= YEnd-Count ; i++) {
752     memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
753     memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
754     memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
755     memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
756     memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
757     SrcPtr = NextLinePtr(SrcPtr);
758     DestPtr = NextLinePtr(DestPtr);
759     }
760     for (i = YEnd+1-Count ; i<=YEnd ; i++) {
761     memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
762     memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
763 doda 4070 memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
764 maya 3393 memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
765     memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
766     DestPtr = NextLinePtr(DestPtr);
767     }
768 maya 3227
769 maya 3393 if (! DispDeleteLines(Count,YEnd)) {
770     BuffUpdateRect(WinOrgX,CursorY,WinOrgX+WinWidth-1,YEnd);
771     }
772 maya 3227 }
773    
774     void BuffDeleteChars(int Count)
775     // Delete characters in current line from cursor
776     // Count: number of characters to be deleted
777     {
778 maya 3393 NewLine(PageStart+CursorY);
779 maya 3227
780 doda 3416 if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
781 maya 3393 EraseKanji(0); /* if cursor is on left harf of a kanji, erase the kanji */
782     EraseKanji(1); /* if cursor on right half... */
783     }
784 maya 3227
785 maya 3393 if (Count > NumOfColumns-CursorX) {
786     Count = NumOfColumns-CursorX;
787     }
788     memmove(&(CodeLine[CursorX]),&(CodeLine[CursorX+Count]),
789     NumOfColumns-Count-CursorX);
790     memmove(&(AttrLine[CursorX]),&(AttrLine[CursorX+Count]),
791     NumOfColumns-Count-CursorX);
792     memmove(&(AttrLine2[CursorX]),&(AttrLine2[CursorX+Count]),
793     NumOfColumns-Count-CursorX);
794     memmove(&(AttrLineFG[CursorX]),&(AttrLineFG[CursorX+Count]),
795     NumOfColumns-Count-CursorX);
796     memmove(&(AttrLineBG[CursorX]),&(AttrLineBG[CursorX+Count]),
797     NumOfColumns-Count-CursorX);
798     memset(&(CodeLine[NumOfColumns-Count]),0x20,Count);
799     memset(&(AttrLine[NumOfColumns-Count]),AttrDefault,Count);
800 doda 4070 memset(&(AttrLine2[NumOfColumns-Count]),CurCharAttr.Attr2 & Attr2ColorMask, Count);
801 maya 3393 memset(&(AttrLineFG[NumOfColumns-Count]),CurCharAttr.Fore,Count);
802     memset(&(AttrLineBG[NumOfColumns-Count]),CurCharAttr.Back,Count);
803 maya 3227
804 maya 3393 BuffUpdateRect(CursorX,CursorY,WinOrgX+WinWidth-1,CursorY);
805 maya 3227 }
806    
807     void BuffEraseChars(int Count)
808     // Erase characters in current line from cursor
809     // Count: number of characters to be deleted
810     {
811 maya 3393 NewLine(PageStart+CursorY);
812 maya 3227
813 doda 3416 if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
814 maya 3393 EraseKanji(0); /* if cursor is on left harf of a kanji, erase the kanji */
815     EraseKanji(1); /* if cursor on right half... */
816     }
817 maya 3227
818 maya 3393 if (Count > NumOfColumns-CursorX) {
819     Count = NumOfColumns-CursorX;
820     }
821     memset(&(CodeLine[CursorX]),0x20,Count);
822     memset(&(AttrLine[CursorX]),AttrDefault,Count);
823 doda 4070 memset(&(AttrLine2[CursorX]),CurCharAttr.Attr2 & Attr2ColorMask, Count);
824 maya 3393 memset(&(AttrLineFG[CursorX]),CurCharAttr.Fore,Count);
825     memset(&(AttrLineBG[CursorX]),CurCharAttr.Back,Count);
826 maya 3227
827 maya 3393 /* update window */
828     DispEraseCharsInLine(CursorX,Count);
829 maya 3227 }
830    
831     void BuffFillWithE()
832     // Fill screen with 'E' characters
833     {
834 maya 3393 LONG TmpPtr;
835     int i;
836 maya 3227
837 maya 3393 TmpPtr = GetLinePtr(PageStart);
838     for (i = 0 ; i <= NumOfLines-1-StatusLine ; i++) {
839     memset(&(CodeBuff[TmpPtr]),'E',NumOfColumns);
840     memset(&(AttrBuff[TmpPtr]),AttrDefault,NumOfColumns);
841     memset(&(AttrBuff2[TmpPtr]),AttrDefault,NumOfColumns);
842     memset(&(AttrBuffFG[TmpPtr]),AttrDefaultFG,NumOfColumns);
843     memset(&(AttrBuffBG[TmpPtr]),AttrDefaultBG,NumOfColumns);
844     TmpPtr = NextLinePtr(TmpPtr);
845     }
846     BuffUpdateRect(WinOrgX,WinOrgY,WinOrgX+WinWidth-1,WinOrgY+WinHeight-1);
847 maya 3227 }
848    
849     void BuffDrawLine(TCharAttr Attr, int Direction, int C)
850     { // IO-8256 terminal
851 maya 3393 LONG Ptr;
852     int i, X, Y;
853 maya 3227
854 maya 3393 if (C==0) {
855     return;
856     }
857     Attr.Attr |= AttrSpecial;
858 maya 3227
859 maya 3393 switch (Direction) {
860     case 3:
861     case 4:
862     if (Direction==3) {
863     if (CursorY==0) {
864     return;
865     }
866     Y = CursorY-1;
867     }
868     else {
869     if (CursorY==NumOfLines-1-StatusLine) {
870     return;
871     }
872     Y = CursorY+1;
873     }
874     if (CursorX+C > NumOfColumns) {
875     C = NumOfColumns-CursorX;
876     }
877     Ptr = GetLinePtr(PageStart+Y);
878     memset(&(CodeBuff[Ptr+CursorX]),'q',C);
879     memset(&(AttrBuff[Ptr+CursorX]),Attr.Attr,C);
880     memset(&(AttrBuff2[Ptr+CursorX]),Attr.Attr2,C);
881     memset(&(AttrBuffFG[Ptr+CursorX]),Attr.Fore,C);
882     memset(&(AttrBuffBG[Ptr+CursorX]),Attr.Back,C);
883     BuffUpdateRect(CursorX,Y,CursorX+C-1,Y);
884     break;
885     case 5:
886     case 6:
887     if (Direction==5) {
888     if (CursorX==0) {
889     return;
890     }
891     X = CursorX - 1;
892     }
893     else {
894     if (CursorX==NumOfColumns-1) {
895     X = CursorX-1;
896     }
897     else {
898     X = CursorX+1;
899     }
900     }
901     Ptr = GetLinePtr(PageStart+CursorY);
902     if (CursorY+C > NumOfLines-StatusLine) {
903     C = NumOfLines-StatusLine-CursorY;
904     }
905     for (i=1; i<=C; i++) {
906     CodeBuff[Ptr+X] = 'x';
907     AttrBuff[Ptr+X] = Attr.Attr;
908     AttrBuff2[Ptr+X] = Attr.Attr2;
909     AttrBuffFG[Ptr+X] = Attr.Fore;
910     AttrBuffBG[Ptr+X] = Attr.Back;
911     Ptr = NextLinePtr(Ptr);
912     }
913     BuffUpdateRect(X,CursorY,X,CursorY+C-1);
914     break;
915     }
916 maya 3227 }
917    
918     void BuffEraseBox
919     (int XStart, int YStart, int XEnd, int YEnd)
920     {
921 maya 3393 int C, i;
922     LONG Ptr;
923 maya 3227
924 maya 3393 if (XEnd>NumOfColumns-1) {
925     XEnd = NumOfColumns-1;
926     }
927     if (YEnd>NumOfLines-1-StatusLine) {
928     YEnd = NumOfLines-1-StatusLine;
929     }
930     if (XStart>XEnd) {
931     return;
932     }
933     if (YStart>YEnd) {
934     return;
935     }
936     C = XEnd-XStart+1;
937     Ptr = GetLinePtr(PageStart+YStart);
938     for (i=YStart; i<=YEnd; i++) {
939     if ((XStart>0) &&
940     ((AttrBuff[Ptr+XStart-1] & AttrKanji) != 0)) {
941     CodeBuff[Ptr+XStart-1] = 0x20;
942     AttrBuff[Ptr+XStart-1] = CurCharAttr.Attr;
943     AttrBuff2[Ptr+XStart-1] = CurCharAttr.Attr2;
944     AttrBuffFG[Ptr+XStart-1] = CurCharAttr.Fore;
945     AttrBuffBG[Ptr+XStart-1] = CurCharAttr.Back;
946     }
947     if ((XStart+C<NumOfColumns) &&
948     ((AttrBuff[Ptr+XStart+C-1] & AttrKanji) != 0)) {
949     CodeBuff[Ptr+XStart+C] = 0x20;
950     AttrBuff[Ptr+XStart+C] = CurCharAttr.Attr;
951     AttrBuff2[Ptr+XStart+C] = CurCharAttr.Attr2;
952     AttrBuffFG[Ptr+XStart+C] = CurCharAttr.Fore;
953     AttrBuffBG[Ptr+XStart+C] = CurCharAttr.Back;
954     }
955     memset(&(CodeBuff[Ptr+XStart]),0x20,C);
956     memset(&(AttrBuff[Ptr+XStart]),AttrDefault,C);
957 doda 4070 memset(&(AttrBuff2[Ptr+XStart]),CurCharAttr.Attr2 & Attr2ColorMask, C);
958 maya 3393 memset(&(AttrBuffFG[Ptr+XStart]),CurCharAttr.Fore,C);
959     memset(&(AttrBuffBG[Ptr+XStart]),CurCharAttr.Back,C);
960     Ptr = NextLinePtr(Ptr);
961     }
962     BuffUpdateRect(XStart,YStart,XEnd,YEnd);
963 maya 3227 }
964    
965 doda 5089 void BuffCopyBox(
966     int SrcXStart, int SrcYStart, int SrcXEnd, int SrcYEnd, int SrcPage,
967     int DstX, int DstY, int DstPage)
968     {
969     int i, C, L;
970     LONG SPtr, DPtr;
971    
972     SrcXStart--;
973     SrcYStart--;
974     SrcXEnd--;
975     SrcYEnd--;
976     SrcPage--;
977     DstX--;
978     DstY--;
979     DstPage--;
980    
981     if (SrcXEnd > NumOfColumns - 1) {
982     SrcXEnd = NumOfColumns-1;
983     }
984     if (SrcYEnd > NumOfLines-1-StatusLine) {
985     SrcYEnd = NumOfColumns-1;
986     }
987     if (SrcXStart > SrcXEnd ||
988     SrcYStart > SrcYEnd ||
989     DstX > NumOfColumns-1 ||
990     DstY > NumOfLines-1-StatusLine) {
991     return;
992     }
993    
994     C = SrcXEnd - SrcXStart + 1;
995     if (DstX + C > NumOfColumns) {
996     C = NumOfColumns - DstX;
997     }
998     L = SrcYEnd - SrcYStart + 1;
999     if (DstY + C > NumOfColumns) {
1000     C = NumOfColumns - DstX;
1001     }
1002    
1003     if (SrcXStart > DstX) {
1004     SPtr = GetLinePtr(PageStart+SrcYStart);
1005     DPtr = GetLinePtr(PageStart+DstY);
1006     for (i=0; i<L; i++) {
1007     memcpy(&(CodeBuff[DPtr+DstX]), &(CodeBuff[SPtr+SrcXStart]), C);
1008     memcpy(&(AttrBuff[DPtr+DstX]), &(AttrBuff[SPtr+SrcXStart]), C);
1009     memcpy(&(AttrBuff2[DPtr+DstX]), &(AttrBuff2[SPtr+SrcXStart]), C);
1010     memcpy(&(AttrBuffFG[DPtr+DstX]), &(AttrBuffFG[SPtr+SrcXStart]), C);
1011     memcpy(&(AttrBuffBG[DPtr+DstX]), &(AttrBuffBG[SPtr+SrcXStart]), C);
1012     SPtr = NextLinePtr(SPtr);
1013     DPtr = NextLinePtr(DPtr);
1014     }
1015     }
1016     else if (SrcXStart < DstX) {
1017     SPtr = GetLinePtr(PageStart+SrcYEnd);
1018     DPtr = GetLinePtr(PageStart+DstY+L-1);
1019     for (i=L; i>0; i--) {
1020     memcpy(&(CodeBuff[DPtr+DstX]), &(CodeBuff[SPtr+SrcXStart]), C);
1021     memcpy(&(AttrBuff[DPtr+DstX]), &(AttrBuff[SPtr+SrcXStart]), C);
1022     memcpy(&(AttrBuff2[DPtr+DstX]), &(AttrBuff2[SPtr+SrcXStart]), C);
1023     memcpy(&(AttrBuffFG[DPtr+DstX]), &(AttrBuffFG[SPtr+SrcXStart]), C);
1024     memcpy(&(AttrBuffBG[DPtr+DstX]), &(AttrBuffBG[SPtr+SrcXStart]), C);
1025     SPtr = PrevLinePtr(SPtr);
1026     DPtr = PrevLinePtr(DPtr);
1027     }
1028     }
1029     else if (SrcYStart != DstY) {
1030     SPtr = GetLinePtr(PageStart+SrcYStart);
1031     DPtr = GetLinePtr(PageStart+DstY);
1032     for (i=0; i<L; i++) {
1033     memmove(&(CodeBuff[DPtr+DstX]), &(CodeBuff[SPtr+SrcXStart]), C);
1034     memmove(&(AttrBuff[DPtr+DstX]), &(AttrBuff[SPtr+SrcXStart]), C);
1035     memmove(&(AttrBuff2[DPtr+DstX]), &(AttrBuff2[SPtr+SrcXStart]), C);
1036     memmove(&(AttrBuffFG[DPtr+DstX]), &(AttrBuffFG[SPtr+SrcXStart]), C);
1037     memmove(&(AttrBuffBG[DPtr+DstX]), &(AttrBuffBG[SPtr+SrcXStart]), C);
1038     SPtr = NextLinePtr(SPtr);
1039     DPtr = NextLinePtr(DPtr);
1040     }
1041     }
1042     BuffUpdateRect(DstX,DstY,DstX+C-1,DstY+L-1);
1043     }
1044    
1045 maya 3227 int LeftHalfOfDBCS(LONG Line, int CharPtr)
1046     // If CharPtr is on the right half of a DBCS character,
1047     // return pointer to the left half
1048     // Line: points to a line in CodeBuff
1049     // CharPtr: points to a char
1050     // return: points to the left half of the DBCS
1051     {
1052 maya 3393 if ((CharPtr>0) &&
1053     ((AttrBuff[Line+CharPtr-1] & AttrKanji) != 0)) {
1054     CharPtr--;
1055     }
1056     return CharPtr;
1057 maya 3227 }
1058    
1059     int MoveCharPtr(LONG Line, int *x, int dx)
1060     // move character pointer x by dx character unit
1061     // in the line specified by Line
1062     // Line: points to a line in CodeBuff
1063     // x: points to a character in the line
1064     // dx: moving distance in character unit (-: left, +: right)
1065 maya 3393 // One DBCS character is counted as one character.
1066 maya 3227 // The pointer stops at the beginning or the end of line.
1067     // Output
1068     // x: new pointer. x points to a SBCS character or
1069     // the left half of a DBCS character.
1070     // return: actual moving distance in character unit
1071     {
1072 maya 3393 int i;
1073 maya 3227
1074 maya 3393 *x = LeftHalfOfDBCS(Line,*x);
1075     i = 0;
1076     while (dx!=0) {
1077     if (dx>0) { // move right
1078     if ((AttrBuff[Line+*x] & AttrKanji) != 0) {
1079     if (*x<NumOfColumns-2) {
1080     i++;
1081     *x = *x + 2;
1082     }
1083     }
1084     else if (*x<NumOfColumns-1) {
1085     i++;
1086     (*x)++;
1087     }
1088     dx--;
1089     }
1090     else { // move left
1091     if (*x>0) {
1092     i--;
1093     (*x)--;
1094     }
1095     *x = LeftHalfOfDBCS(Line,*x);
1096     dx++;
1097     }
1098 maya 3227 }
1099 maya 3393 return i;
1100 maya 3227 }
1101    
1102     void BuffCBCopy(BOOL Table)
1103     // copy selected text to clipboard
1104     {
1105 maya 3393 LONG MemSize;
1106     PCHAR CBPtr;
1107     LONG TmpPtr;
1108     int i, j, k, IStart, IEnd;
1109     BOOL Sp, FirstChar;
1110     BYTE b;
1111 maya 3227 #ifndef NO_COPYLINE_FIX
1112 maya 3393 BOOL LineContinued, PrevLineContinued;
1113     LineContinued = FALSE;
1114 maya 3227 #endif /* NO_COPYLINE_FIX */
1115    
1116 maya 3393 if (TalkStatus==IdTalkCB) {
1117     return;
1118     }
1119     if (! Selected) {
1120     return;
1121     }
1122 maya 3227
1123     // --- open clipboard and get CB memory
1124 maya 3393 if (BoxSelect) {
1125     MemSize = (SelectEnd.x-SelectStart.x+3)*
1126     (SelectEnd.y-SelectStart.y+1) + 1;
1127     }
1128     else {
1129     MemSize = (SelectEnd.y-SelectStart.y)*
1130     (NumOfColumns+2) +
1131     SelectEnd.x - SelectStart.x + 1;
1132     }
1133     CBPtr = CBOpen(MemSize);
1134     if (CBPtr==NULL) {
1135     return;
1136     }
1137 maya 3227
1138     // --- copy selected text to CB memory
1139 maya 3393 LockBuffer();
1140 maya 3227
1141 maya 3393 CBPtr[0] = 0;
1142     TmpPtr = GetLinePtr(SelectStart.y);
1143     k = 0;
1144     for (j = SelectStart.y ; j<=SelectEnd.y ; j++) {
1145     if (BoxSelect) {
1146     IStart = SelectStart.x;
1147     IEnd = SelectEnd.x-1;
1148     }
1149     else {
1150     IStart = 0;
1151     IEnd = NumOfColumns-1;
1152     if (j==SelectStart.y) {
1153     IStart = SelectStart.x;
1154     }
1155     if (j==SelectEnd.y) {
1156     IEnd = SelectEnd.x-1;
1157     }
1158     }
1159     i = LeftHalfOfDBCS(TmpPtr,IStart);
1160     if (i!=IStart) {
1161     if (j==SelectStart.y) {
1162     IStart = i;
1163     }
1164     else {
1165     IStart = i + 2;
1166     }
1167     }
1168 maya 3227
1169 maya 3393 // exclude right-side space characters
1170     IEnd = LeftHalfOfDBCS(TmpPtr,IEnd);
1171 maya 3227 #ifndef NO_COPYLINE_FIX
1172 maya 3393 PrevLineContinued = LineContinued;
1173     LineContinued = FALSE;
1174     if (ts.EnableContinuedLineCopy && j!=SelectEnd.y && !BoxSelect) {
1175     LONG NextTmpPtr = NextLinePtr(TmpPtr);
1176     if ((AttrBuff[NextTmpPtr] & AttrLineContinued) != 0) {
1177     LineContinued = TRUE;
1178     }
1179     if (IEnd == NumOfColumns-1 &&
1180     (AttrBuff[TmpPtr + IEnd] & AttrLineContinued) != 0) {
1181     MoveCharPtr(TmpPtr,&IEnd,-1);
1182     }
1183     }
1184     if (!LineContinued)
1185 maya 3227 #endif /* NO_COPYLINE_FIX */
1186 maya 3393 while ((IEnd>0) && (CodeBuff[TmpPtr+IEnd]==0x20)) {
1187     MoveCharPtr(TmpPtr,&IEnd,-1);
1188     }
1189     if ((IEnd==0) && (CodeBuff[TmpPtr]==0x20)) {
1190     IEnd = -1;
1191     }
1192     else if ((AttrBuff[TmpPtr+IEnd] & AttrKanji) != 0) { /* DBCS first byte? */
1193     IEnd++;
1194     }
1195 maya 3227
1196 maya 3393 Sp = FALSE;
1197     FirstChar = TRUE;
1198     i = IStart;
1199     while (i <= IEnd) {
1200     b = CodeBuff[TmpPtr+i];
1201     i++;
1202     if (! Sp) {
1203     if ((Table) && (b<=0x20)) {
1204     Sp = TRUE;
1205     b = 0x09;
1206     }
1207 maya 3227 #ifndef NO_COPYLINE_FIX
1208 maya 3393 if ((b!=0x09) || (! FirstChar) || PrevLineContinued) {
1209 maya 3227 #else
1210 maya 3393 if ((b!=0x09) || (! FirstChar)) {
1211 maya 3227 #endif
1212 maya 3393 FirstChar = FALSE;
1213     CBPtr[k] = b;
1214     k++;
1215     }
1216     }
1217     else {
1218     if (b>0x20) {
1219     Sp = FALSE;
1220     FirstChar = FALSE;
1221     CBPtr[k] = b;
1222     k++;
1223     }
1224     }
1225     }
1226 maya 3227
1227     #ifndef NO_COPYLINE_FIX
1228 maya 3393 if (!LineContinued)
1229 maya 3227 #endif /* NO_COPYLINE_FIX */
1230 maya 3393 if (j < SelectEnd.y) {
1231     CBPtr[k] = 0x0d;
1232     k++;
1233     CBPtr[k] = 0x0a;
1234     k++;
1235     }
1236 maya 3227
1237 maya 3393 TmpPtr = NextLinePtr(TmpPtr);
1238     }
1239     CBPtr[k] = 0;
1240 maya 3227 #ifndef NO_COPYLINE_FIX
1241 maya 3393 LineContinued = FALSE;
1242     if (ts.EnableContinuedLineCopy && j!=SelectEnd.y && !BoxSelect && j<BuffEnd-1) {
1243     LONG NextTmpPtr = NextLinePtr(TmpPtr);
1244     if ((AttrBuff[NextTmpPtr] & AttrLineContinued) != 0) {
1245     LineContinued = TRUE;
1246     }
1247     if (IEnd == NumOfColumns-1 &&
1248     (AttrBuff[TmpPtr + IEnd] & AttrLineContinued) != 0) {
1249     MoveCharPtr(TmpPtr,&IEnd,-1);
1250     }
1251     }
1252     if (!LineContinued)
1253 maya 3227 #endif /* NO_COPYLINE_FIX */
1254 maya 3393 UnlockBuffer();
1255 maya 3227
1256     // --- send CB memory to clipboard
1257 maya 3393 CBClose();
1258     return;
1259 maya 3227 }
1260    
1261     void BuffPrint(BOOL ScrollRegion)
1262     // Print screen or selected text
1263     {
1264 maya 3393 int Id;
1265     POINT PrintStart, PrintEnd;
1266     TCharAttr CurAttr, TempAttr;
1267     int i, j, count;
1268     int IStart, IEnd;
1269     LONG TmpPtr;
1270 maya 3227
1271 maya 3393 TempAttr = DefCharAttr;
1272 maya 3227
1273 maya 3393 if (ScrollRegion) {
1274     Id = VTPrintInit(IdPrnScrollRegion);
1275     }
1276     else if (Selected) {
1277     Id = VTPrintInit(IdPrnScreen | IdPrnSelectedText);
1278     }
1279     else {
1280     Id = VTPrintInit(IdPrnScreen);
1281     }
1282     if (Id==IdPrnCancel) {
1283     return;
1284     }
1285 maya 3227
1286 maya 3393 /* set print region */
1287     if (Id==IdPrnSelectedText) {
1288     /* print selected region */
1289     PrintStart = SelectStart;
1290     PrintEnd = SelectEnd;
1291     }
1292     else if (Id==IdPrnScrollRegion) {
1293     /* print scroll region */
1294     PrintStart.x = 0;
1295     PrintStart.y = PageStart + CursorTop;
1296     PrintEnd.x = NumOfColumns;
1297     PrintEnd.y = PageStart + CursorBottom;
1298     }
1299     else {
1300     /* print current screen */
1301     PrintStart.x = 0;
1302     PrintStart.y = PageStart;
1303     PrintEnd.x = NumOfColumns;
1304     PrintEnd.y = PageStart + NumOfLines - 1;
1305     }
1306     if (PrintEnd.y > BuffEnd-1) {
1307     PrintEnd.y = BuffEnd-1;
1308     }
1309 maya 3227
1310 maya 3393 LockBuffer();
1311 maya 3227
1312 maya 3393 TmpPtr = GetLinePtr(PrintStart.y);
1313     for (j = PrintStart.y ; j <= PrintEnd.y ; j++) {
1314     if (j==PrintStart.y) {
1315     IStart = PrintStart.x;
1316     }
1317     else {
1318     IStart = 0;
1319     }
1320     if (j == PrintEnd.y) {
1321     IEnd = PrintEnd.x - 1;
1322     }
1323     else {
1324     IEnd = NumOfColumns - 1;
1325     }
1326 maya 3227
1327 maya 3393 while ((IEnd>=IStart) &&
1328     (CodeBuff[TmpPtr+IEnd]==0x20) &&
1329     (AttrBuff[TmpPtr+IEnd]==AttrDefault) &&
1330     (AttrBuff2[TmpPtr+IEnd]==AttrDefault)) {
1331     IEnd--;
1332     }
1333 maya 3227
1334 maya 3393 i = IStart;
1335     while (i <= IEnd) {
1336     CurAttr.Attr = AttrBuff[TmpPtr+i] & ~ AttrKanji;
1337     CurAttr.Attr2 = AttrBuff2[TmpPtr+i];
1338     CurAttr.Fore = AttrBuffFG[TmpPtr+i];
1339     CurAttr.Back = AttrBuffBG[TmpPtr+i];
1340 maya 3227
1341 maya 3393 count = 1;
1342     while ((i+count <= IEnd) &&
1343     (CurAttr.Attr == (AttrBuff[TmpPtr+i+count] & ~ AttrKanji)) &&
1344     (CurAttr.Attr2 == AttrBuff2[TmpPtr+i+count]) &&
1345     (CurAttr.Fore == AttrBuffFG[TmpPtr+i+count]) &&
1346     (CurAttr.Back == AttrBuffBG[TmpPtr+i+count]) ||
1347     (i+count<NumOfColumns) &&
1348     ((AttrBuff[TmpPtr+i+count-1] & AttrKanji) != 0)) {
1349     count++;
1350     }
1351 maya 3227
1352 maya 3393 if (TCharAttrCmp(CurAttr, TempAttr) != 0) {
1353     PrnSetAttr(CurAttr);
1354     TempAttr = CurAttr;
1355     }
1356     PrnOutText(&(CodeBuff[TmpPtr+i]),count);
1357     i = i+count;
1358     }
1359     PrnNewLine();
1360     TmpPtr = NextLinePtr(TmpPtr);
1361     }
1362 maya 3227
1363 maya 3393 UnlockBuffer();
1364     VTPrintEnd();
1365 maya 3227 }
1366    
1367     void BuffDumpCurrentLine(BYTE TERM)
1368     // Dumps current line to the file (for path through printing)
1369     // HFile: file handle
1370     // TERM: terminator character
1371     // = LF or VT or FF
1372     {
1373 maya 3393 int i, j;
1374 maya 3227
1375 maya 3393 i = NumOfColumns;
1376     while ((i>0) && (CodeLine[i-1]==0x20)) {
1377     i--;
1378     }
1379     for (j=0; j<i; j++) {
1380     WriteToPrnFile(CodeLine[j],FALSE);
1381     }
1382     WriteToPrnFile(0,TRUE);
1383     if ((TERM>=LF) && (TERM<=FF)) {
1384     WriteToPrnFile(0x0d,FALSE);
1385     WriteToPrnFile(TERM,TRUE);
1386     }
1387 maya 3227 }
1388    
1389    
1390     /* begin - ishizaki */
1391     static void markURL(int x)
1392     {
1393     #ifdef URL_EMPHASIS
1394 yutakapon 3414 // RFC3986(Uniform Resource Identifier (URI): Generic Syntax)に準拠する
1395 maya 3227 // by sakura editor 1.5.2.1: etc_uty.cpp
1396     static const char url_char[] = {
1397     /* +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F */
1398     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* +00: */
1399     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* +10: */
1400     0, -1, 0, -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, -1, /* +20: " !"#$%&'()*+,-./" */
1401     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, -1, /* +30: "0123456789:;<=>?" */
1402     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* +40: "@ABCDEFGHIJKLMNO" */
1403     -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, 0, -1, /* +50: "PQRSTUVWXYZ[\]^_" */
1404     0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* +60: "`abcdefghijklmno" */
1405 yutakapon 3414 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, -1, 0, /* +70: "pqrstuvwxyz{|}~ " */
1406 maya 3227 /* 0 : not url char
1407     * -1 : url char
1408     * other: url head char --> url_table array number + 1
1409     */
1410     };
1411 yutakapon 3614 static char *prefix[] = {
1412     "https://",
1413     "http://",
1414     "sftp://",
1415     "tftp://",
1416     "news://",
1417     "ftp://",
1418     "mms://",
1419     NULL
1420     };
1421 maya 3227 unsigned char ch = CodeLine[x];
1422    
1423 yutakapon 3615 if (ts.EnableClickableUrl == FALSE &&
1424     (ts.ColorFlag & CF_URLCOLOR) == 0)
1425 maya 3227 return;
1426    
1427     // 直前の行から連結しているか。
1428     // TODO: 1つ前の行の終端文字が URL の一部なら、強制的に現在の行頭文字もURLの一部とみなす。
1429     // (2005.4.3 yutaka)
1430     if (x == 0) {
1431     if (AttrLine > AttrBuff && (AttrLine[x-1] & AttrURL)) {
1432     if (!(ch & 0x80 || url_char[ch]==0)) { // かつURL構成文字なら
1433 doda 3642 AttrLine[x] |= AttrURL;
1434 maya 3227 }
1435     }
1436     return;
1437     }
1438    
1439     if ((x-1>=0) && (AttrLine[x-1] & AttrURL) &&
1440     !(ch & 0x80 || url_char[ch]==0)) {
1441     // !((CodeLine[x] <= ' ') && !(AttrLine[x] & AttrKanji))) {
1442 doda 3642 AttrLine[x] |= AttrURL;
1443 maya 3227 return;
1444     }
1445    
1446     if ((x-2>=0) && !strncmp(&CodeLine[x-2], "://", 3)) {
1447 maya 3417 int i, len = -1;
1448 yutakapon 3608 RECT rc;
1449     int CaretX, CaretY;
1450 yutakapon 3614 char **p = prefix;
1451 yutakapon 3608
1452 yutakapon 3614 while (*p) {
1453     len = strlen(*p) - 1;
1454     if ((x-len>=0) && !strncmp(&CodeLine[x-len], *p, len)) {
1455     for (i = 0; i <= len; i++) {
1456 doda 3642 AttrLine[x-i] |= AttrURL;
1457 yutakapon 3614 }
1458     break;
1459     }
1460     p++;
1461 maya 3227 }
1462 yutakapon 3608
1463     /* ハイパーリンクの色属性変更は、すでに画面へ出力後に、バッファを遡って URL 属性を
1464     * 付け直すというロジックであるため、色が正しく描画されない場合がある。
1465     * 少々強引だが、ハイパーリンクを発見したタイミングで、その行に再描画指示を出すことで、
1466     * リアルタイムな色描画を実現する。
1467     * (2009.8.26 yutaka)
1468     */
1469     CaretX = (0-WinOrgX)*FontWidth;
1470     CaretY = (CursorY-WinOrgY)*FontHeight;
1471     rc.left = CaretX;
1472     rc.top = CaretY;
1473     rc.right = CaretX + NumOfColumns * FontWidth;
1474     rc.bottom = CaretY + FontHeight;
1475     InvalidateRect(HVTWin, &rc, FALSE);
1476 maya 3227 }
1477     #endif
1478     }
1479     /* end - ishizaki */
1480    
1481     void BuffPutChar(BYTE b, TCharAttr Attr, BOOL Insert)
1482     // Put a character in the buffer at the current position
1483     // b: character
1484     // Attr: attributes
1485     // Insert: Insert flag
1486     {
1487 maya 3393 int XStart;
1488 maya 3227
1489 doda 3312 #ifndef NO_COPYLINE_FIX
1490 maya 3393 if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
1491     Attr.Attr |= AttrLineContinued;
1492     }
1493 doda 3312 #endif /* NO_COPYLINE_FIX */
1494    
1495 doda 3416 if (ts.Language==IdJapanese || ts.Language==IdKorean || ts.Language==IdUtf8) {
1496 maya 3393 EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
1497     if (! Insert) {
1498     EraseKanji(0); /* if cursor on left half... */
1499     }
1500     }
1501 maya 3227
1502 maya 3393 if (Insert) {
1503     memmove(&CodeLine[CursorX+1],&CodeLine[CursorX],NumOfColumns-1-CursorX);
1504     memmove(&AttrLine[CursorX+1],&AttrLine[CursorX],NumOfColumns-1-CursorX);
1505     memmove(&AttrLine2[CursorX+1],&AttrLine2[CursorX],NumOfColumns-1-CursorX);
1506     memmove(&AttrLineFG[CursorX+1],&AttrLineFG[CursorX],NumOfColumns-1-CursorX);
1507     memmove(&AttrLineBG[CursorX+1],&AttrLineBG[CursorX],NumOfColumns-1-CursorX);
1508     CodeLine[CursorX] = b;
1509     AttrLine[CursorX] = Attr.Attr;
1510     AttrLine2[CursorX] = Attr.Attr2;
1511     AttrLineFG[CursorX] = Attr.Fore;
1512     AttrLineBG[CursorX] = Attr.Back;
1513     /* last char in current line is kanji first? */
1514     if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0) {
1515     /* then delete it */
1516     CodeLine[NumOfColumns-1] = 0x20;
1517     AttrLine[NumOfColumns-1] = CurCharAttr.Attr;
1518     AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
1519     AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
1520     AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
1521     }
1522     /* begin - ishizaki */
1523     markURL(CursorX+1);
1524     markURL(CursorX);
1525     /* end - ishizaki */
1526 maya 3227
1527 maya 3393 if (StrChangeCount==0) {
1528     XStart = CursorX;
1529     }
1530     else {
1531     XStart = StrChangeStart;
1532     }
1533     StrChangeCount = 0;
1534     BuffUpdateRect(XStart,CursorY,NumOfColumns-1,CursorY);
1535     }
1536     else {
1537     CodeLine[CursorX] = b;
1538     AttrLine[CursorX] = Attr.Attr;
1539     AttrLine2[CursorX] = Attr.Attr2;
1540     AttrLineFG[CursorX] = Attr.Fore;
1541     AttrLineBG[CursorX] = Attr.Back;
1542     /* begin - ishizaki */
1543     markURL(CursorX);
1544     /* end - ishizaki */
1545 maya 3227
1546 maya 3393 if (StrChangeCount==0) {
1547     StrChangeStart = CursorX;
1548     }
1549     StrChangeCount++;
1550     }
1551 maya 3227 }
1552    
1553     void BuffPutKanji(WORD w, TCharAttr Attr, BOOL Insert)
1554     // Put a kanji character in the buffer at the current position
1555     // b: character
1556     // Attr: attributes
1557     // Insert: Insert flag
1558     {
1559 maya 3393 int XStart;
1560 maya 3227
1561 doda 3312 #ifndef NO_COPYLINE_FIX
1562 maya 3393 if (ts.EnableContinuedLineCopy && CursorX == 0 && (AttrLine[0] & AttrLineContinued)) {
1563     Attr.Attr |= AttrLineContinued;
1564     }
1565 doda 3312 #endif /* NO_COPYLINE_FIX */
1566    
1567 maya 3393 EraseKanji(1); /* if cursor is on right half of a kanji, erase the kanji */
1568 maya 3227
1569 maya 3393 if (Insert) {
1570     memmove(&CodeLine[CursorX+2],&CodeLine[CursorX],NumOfColumns-2-CursorX);
1571     memmove(&AttrLine[CursorX+2],&AttrLine[CursorX],NumOfColumns-2-CursorX);
1572     memmove(&AttrLine2[CursorX+2],&AttrLine2[CursorX],NumOfColumns-2-CursorX);
1573     memmove(&AttrLineFG[CursorX+2],&AttrLineFG[CursorX],NumOfColumns-2-CursorX);
1574     memmove(&AttrLineBG[CursorX+2],&AttrLineBG[CursorX],NumOfColumns-2-CursorX);
1575 maya 3227
1576 maya 3393 CodeLine[CursorX] = HIBYTE(w);
1577     AttrLine[CursorX] = Attr.Attr | AttrKanji; /* DBCS first byte */
1578     AttrLine2[CursorX] = Attr.Attr2;
1579     AttrLineFG[CursorX] = Attr.Fore;
1580     AttrLineBG[CursorX] = Attr.Back;
1581     if (CursorX < NumOfColumns-1) {
1582     CodeLine[CursorX+1] = LOBYTE(w);
1583     AttrLine[CursorX+1] = Attr.Attr;
1584     AttrLine2[CursorX+1] = Attr.Attr2;
1585     AttrLineFG[CursorX+1] = Attr.Fore;
1586     AttrLineBG[CursorX+1] = Attr.Back;
1587     }
1588     /* begin - ishizaki */
1589     markURL(CursorX);
1590     markURL(CursorX+1);
1591     /* end - ishizaki */
1592 maya 3227
1593 maya 3393 /* last char in current line is kanji first? */
1594     if ((AttrLine[NumOfColumns-1] & AttrKanji) != 0) {
1595     /* then delete it */
1596     CodeLine[NumOfColumns-1] = 0x20;
1597     AttrLine[NumOfColumns-1] = CurCharAttr.Attr;
1598     AttrLine2[NumOfColumns-1] = CurCharAttr.Attr2;
1599     AttrLineFG[NumOfColumns-1] = CurCharAttr.Fore;
1600     AttrLineBG[NumOfColumns-1] = CurCharAttr.Back;
1601     }
1602 maya 3227
1603 maya 3393 if (StrChangeCount==0) {
1604     XStart = CursorX;
1605     }
1606     else {
1607     XStart = StrChangeStart;
1608     }
1609     StrChangeCount = 0;
1610     BuffUpdateRect(XStart,CursorY,NumOfColumns-1,CursorY);
1611     }
1612     else {
1613     CodeLine[CursorX] = HIBYTE(w);
1614     AttrLine[CursorX] = Attr.Attr | AttrKanji; /* DBCS first byte */
1615     AttrLine2[CursorX] = Attr.Attr2;
1616     AttrLineFG[CursorX] = Attr.Fore;
1617     AttrLineBG[CursorX] = Attr.Back;
1618     if (CursorX < NumOfColumns-1) {
1619     CodeLine[CursorX+1] = LOBYTE(w);
1620     AttrLine[CursorX+1] = Attr.Attr;
1621     AttrLine2[CursorX+1] = Attr.Attr2;
1622     AttrLineFG[CursorX+1] = Attr.Fore;
1623     AttrLineBG[CursorX+1] = Attr.Back;
1624     }
1625     /* begin - ishizaki */
1626     markURL(CursorX);
1627     markURL(CursorX+1);
1628     /* end - ishizaki */
1629 maya 3227
1630 maya 3393 if (StrChangeCount==0) {
1631     StrChangeStart = CursorX;
1632     }
1633     StrChangeCount = StrChangeCount + 2;
1634     }
1635 maya 3227 }
1636    
1637     BOOL CheckSelect(int x, int y)
1638     // subroutine called by BuffUpdateRect
1639     {
1640 maya 3393 LONG L, L1, L2;
1641 maya 3227
1642 maya 3393 if (BoxSelect) {
1643     return (Selected &&
1644     ((SelectStart.x<=x) && (x<SelectEnd.x) ||
1645     (SelectEnd.x<=x) && (x<SelectStart.x)) &&
1646     ((SelectStart.y<=y) && (y<=SelectEnd.y) ||
1647     (SelectEnd.y<=y) && (y<=SelectStart.y)));
1648     }
1649     else {
1650     L = MAKELONG(x,y);
1651     L1 = MAKELONG(SelectStart.x,SelectStart.y);
1652     L2 = MAKELONG(SelectEnd.x,SelectEnd.y);
1653 maya 3227
1654 maya 3393 return (Selected &&
1655     ((L1<=L) && (L<L2) || (L2<=L) && (L<L1)));
1656     }
1657 maya 3227 }
1658    
1659     void BuffUpdateRect
1660     (int XStart, int YStart, int XEnd, int YEnd)
1661     // Display text in a rectangular region in the screen
1662     // XStart: x position of the upper-left corner (screen cordinate)
1663     // YStart: y position
1664     // XEnd: x position of the lower-right corner (last character)
1665     // YEnd: y position
1666     {
1667 maya 3393 int i, j, count;
1668     int IStart, IEnd;
1669     int X, Y;
1670     LONG TmpPtr;
1671     TCharAttr CurAttr, TempAttr;
1672     BOOL CurSel, TempSel, Caret;
1673 maya 3227
1674 maya 3393 if (XStart >= WinOrgX+WinWidth) {
1675     return;
1676     }
1677     if (YStart >= WinOrgY+WinHeight) {
1678     return;
1679     }
1680     if (XEnd < WinOrgX) {
1681     return;
1682     }
1683     if (YEnd < WinOrgY) {
1684     return;
1685     }
1686 maya 3227
1687 maya 3393 if (XStart < WinOrgX) {
1688     XStart = WinOrgX;
1689     }
1690     if (YStart < WinOrgY) {
1691     YStart = WinOrgY;
1692     }
1693     if (XEnd >= WinOrgX+WinWidth) {
1694     XEnd = WinOrgX+WinWidth-1;
1695     }
1696     if (YEnd >= WinOrgY+WinHeight) {
1697     YEnd = WinOrgY+WinHeight-1;
1698     }
1699 maya 3227
1700 maya 3393 TempAttr = DefCharAttr;
1701     TempSel = FALSE;
1702 maya 3227
1703 maya 3393 Caret = IsCaretOn();
1704     if (Caret) {
1705     CaretOff();
1706     }
1707 maya 3227
1708 maya 3393 DispSetupDC(DefCharAttr, TempSel);
1709 maya 3227
1710 maya 3393 Y = (YStart-WinOrgY)*FontHeight;
1711     TmpPtr = GetLinePtr(PageStart+YStart);
1712     for (j = YStart+PageStart ; j <= YEnd+PageStart ; j++) {
1713     IStart = XStart;
1714     IEnd = XEnd;
1715 maya 3227
1716 maya 3393 IStart = LeftHalfOfDBCS(TmpPtr,IStart);
1717 maya 3227
1718 maya 3393 X = (IStart-WinOrgX)*FontWidth;
1719 maya 3227
1720 maya 3393 i = IStart;
1721     do {
1722     CurAttr.Attr = AttrBuff[TmpPtr+i] & ~ AttrKanji;
1723     CurAttr.Attr2 = AttrBuff2[TmpPtr+i];
1724     CurAttr.Fore = AttrBuffFG[TmpPtr+i];
1725     CurAttr.Back = AttrBuffBG[TmpPtr+i];
1726     CurSel = CheckSelect(i,j);
1727     count = 1;
1728     while ( (i+count <= IEnd) &&
1729     (CurAttr.Attr == (AttrBuff[TmpPtr+i+count] & ~ AttrKanji)) &&
1730     (CurAttr.Attr2==AttrBuff2[TmpPtr+i+count]) &&
1731     (CurAttr.Fore==AttrBuffFG[TmpPtr+i+count]) &&
1732     (CurAttr.Back==AttrBuffBG[TmpPtr+i+count]) &&
1733     (CurSel==CheckSelect(i+count,j)) ||
1734     (i+count<NumOfColumns) &&
1735     ((AttrBuff[TmpPtr+i+count-1] & AttrKanji) != 0) ) {
1736     count++;
1737     }
1738 maya 3227
1739 maya 3393 if (TCharAttrCmp(CurAttr, TempAttr) != 0 || (CurSel != TempSel)) {
1740     DispSetupDC(CurAttr, CurSel);
1741     TempAttr = CurAttr;
1742     TempSel = CurSel;
1743     }
1744     DispStr(&CodeBuff[TmpPtr+i],count,Y, &X);
1745     i = i+count;
1746     }
1747     while (i<=IEnd);
1748     Y = Y + FontHeight;
1749     TmpPtr = NextLinePtr(TmpPtr);
1750     }
1751     if (Caret) {
1752     CaretOn();
1753     }
1754 maya 3227 }
1755    
1756     void UpdateStr()
1757     // Display not-yet-displayed string
1758     {
1759 maya 3393 int X, Y;
1760     TCharAttr TempAttr;
1761 yutakapon 3656 int pos, len;
1762 maya 3227
1763 maya 3393 if (StrChangeCount==0) {
1764     return;
1765     }
1766     X = StrChangeStart;
1767     Y = CursorY;
1768     if (! IsLineVisible(&X, &Y)) {
1769     StrChangeCount = 0;
1770     return;
1771     }
1772 maya 3227
1773 maya 3393 TempAttr.Attr = AttrLine[StrChangeStart];
1774     TempAttr.Attr2 = AttrLine2[StrChangeStart];
1775     TempAttr.Fore = AttrLineFG[StrChangeStart];
1776     TempAttr.Back = AttrLineBG[StrChangeStart];
1777 yutakapon 3656
1778     /* これから描画する文字列の始まりが「URL構成文字属性」だった場合、
1779     * 当該色で行末までペイントされないようにする。
1780     * (2009.10.24 yutaka)
1781     */
1782 doda 3659 if (TempAttr.Attr & AttrURL) {
1783 yutakapon 3656 /* 開始位置からどこまでが AttrURL かをカウントする */
1784     len = 0;
1785     for (pos = 0 ; pos < StrChangeCount ; pos++) {
1786     if (TempAttr.Attr != AttrLine[StrChangeStart + pos])
1787     break;
1788     len++;
1789     }
1790     DispSetupDC(TempAttr, FALSE);
1791     DispStr(&CodeLine[StrChangeStart], len, Y, &X);
1792    
1793     /* 残りの文字列があれば、ふつうに描画を行う。*/
1794     if (len < StrChangeCount) {
1795     TempAttr.Attr = AttrLine[StrChangeStart + pos];
1796     TempAttr.Attr2 = AttrLine2[StrChangeStart + pos];
1797     TempAttr.Fore = AttrLineFG[StrChangeStart + pos];
1798     TempAttr.Back = AttrLineBG[StrChangeStart + pos];
1799    
1800     DispSetupDC(TempAttr, FALSE);
1801     DispStr(&CodeLine[StrChangeStart + pos], (StrChangeCount - len), Y, &X);
1802     }
1803     } else {
1804     DispSetupDC(TempAttr, FALSE);
1805     DispStr(&CodeLine[StrChangeStart],StrChangeCount,Y, &X);
1806     }
1807    
1808 maya 3393 StrChangeCount = 0;
1809 maya 3227 }
1810    
1811     #if 0
1812     void UpdateStrUnicode(void)
1813     // Display not-yet-displayed string
1814     {
1815     int X, Y;
1816     TCharAttr TempAttr;
1817    
1818     if (StrChangeCount==0) return;
1819     X = StrChangeStart;
1820     Y = CursorY;
1821     if (! IsLineVisible(&X, &Y))
1822     {
1823     StrChangeCount = 0;
1824     return;
1825     }
1826    
1827     TempAttr.Attr = AttrLine[StrChangeStart];
1828     TempAttr.Attr2 = AttrLine2[StrChangeStart];
1829     TempAttr.Fore = AttrLineFG[StrChangeStart];
1830     TempAttr.Back = AttrLineBG[StrChangeStart];
1831     DispSetupDC(TempAttr, FALSE);
1832     DispStr(&CodeLine[StrChangeStart],StrChangeCount,Y, &X);
1833     StrChangeCount = 0;
1834     }
1835     #endif
1836    
1837     void MoveCursor(int Xnew, int Ynew)
1838     {
1839 maya 3393 UpdateStr();
1840 maya 3227
1841 maya 3393 if (CursorY!=Ynew) {
1842     NewLine(PageStart+Ynew);
1843     }
1844 maya 3227
1845 maya 3393 CursorX = Xnew;
1846     CursorY = Ynew;
1847     Wrap = FALSE;
1848 maya 3227
1849 maya 3393 /* 最下行でだけ自動スクロールする*/
1850 doda 4469 if (ts.AutoScrollOnlyInBottomLine == 0 || WinOrgY == 0) {
1851 maya 3393 DispScrollToCursor(CursorX, CursorY);
1852     }
1853 maya 3227 }
1854    
1855     void MoveRight()
1856     /* move cursor right, but dont update screen.
1857     this procedure must be called from DispChar&DispKanji only */
1858     {
1859 maya 3393 CursorX++;
1860     /* 最下行でだけ自動スクロールする */
1861 doda 4469 if (ts.AutoScrollOnlyInBottomLine == 0 || WinOrgY == 0) {
1862 maya 3393 DispScrollToCursor(CursorX, CursorY);
1863     }
1864 maya 3227 }
1865    
1866     void BuffSetCaretWidth()
1867     {
1868 maya 3393 BOOL DW;
1869 maya 3227
1870 maya 3393 /* check whether cursor on a DBCS character */
1871     DW = (((BYTE)(AttrLine[CursorX]) & AttrKanji) != 0);
1872     DispSetCaretWidth(DW);
1873 maya 3227 }
1874    
1875     void ScrollUp1Line()
1876     {
1877 maya 3393 int i;
1878     LONG SrcPtr, DestPtr;
1879 maya 3227
1880 maya 3393 if ((CursorTop<=CursorY) && (CursorY<=CursorBottom)) {
1881     UpdateStr();
1882 maya 3227
1883 maya 3393 DestPtr = GetLinePtr(PageStart+CursorBottom);
1884     for (i = CursorBottom-1 ; i >= CursorTop ; i--) {
1885     SrcPtr = PrevLinePtr(DestPtr);
1886     memcpy(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
1887     memcpy(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
1888     memcpy(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
1889     memcpy(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
1890     memcpy(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
1891     DestPtr = SrcPtr;
1892     }
1893     memset(&(CodeBuff[SrcPtr]),0x20,NumOfColumns);
1894     memset(&(AttrBuff[SrcPtr]),AttrDefault,NumOfColumns);
1895 doda 4070 memset(&(AttrBuff2[SrcPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
1896 maya 3393 memset(&(AttrBuffFG[SrcPtr]),CurCharAttr.Fore,NumOfColumns);
1897     memset(&(AttrBuffBG[SrcPtr]),CurCharAttr.Back,NumOfColumns);
1898 maya 3227
1899 maya 3393 DispScrollNLines(CursorTop,CursorBottom,-1);
1900     }
1901 maya 3227 }
1902    
1903     void BuffScrollNLines(int n)
1904     {
1905 maya 3393 int i;
1906     LONG SrcPtr, DestPtr;
1907 maya 3227
1908 maya 3393 if (n<1) {
1909     return;
1910     }
1911     UpdateStr();
1912 maya 3227
1913 maya 3393 if ((CursorTop == 0) && (CursorBottom == NumOfLines-1)) {
1914     WinOrgY = WinOrgY-n;
1915     /* 最下行でだけ自動スクロールする */
1916 doda 4469 if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
1917 maya 3393 NewOrgY = WinOrgY;
1918     }
1919     BuffScroll(n,CursorBottom);
1920     DispCountScroll(n);
1921     }
1922     else if ((CursorTop==0) && (CursorY<=CursorBottom)) {
1923     /* 最下行でだけ自動スクロールする */
1924 doda 4469 if (ts.AutoScrollOnlyInBottomLine != 0 && NewOrgY != 0) {
1925 maya 3393 /* スクロールさせない場合の処理 */
1926     WinOrgY = WinOrgY-n;
1927     NewOrgY = WinOrgY;
1928     BuffScroll(n,CursorBottom);
1929     DispCountScroll(n);
1930     } else {
1931     BuffScroll(n,CursorBottom);
1932     DispScrollNLines(WinOrgY,CursorBottom,n);
1933     }
1934     }
1935     else if ((CursorTop<=CursorY) && (CursorY<=CursorBottom)) {
1936     DestPtr = GetLinePtr(PageStart+CursorTop);
1937     if (n<CursorBottom-CursorTop+1) {
1938     SrcPtr = GetLinePtr(PageStart+CursorTop+n);
1939     for (i = CursorTop+n ; i<=CursorBottom ; i++) {
1940     memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
1941     memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
1942     memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
1943     memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
1944     memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
1945     SrcPtr = NextLinePtr(SrcPtr);
1946     DestPtr = NextLinePtr(DestPtr);
1947     }
1948     }
1949     else {
1950     n = CursorBottom-CursorTop+1;
1951     }
1952     for (i = CursorBottom+1-n ; i<=CursorBottom; i++) {
1953     memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
1954     memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
1955 doda 4070 memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
1956 maya 3393 memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
1957     memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
1958     DestPtr = NextLinePtr(DestPtr);
1959     }
1960     DispScrollNLines(CursorTop,CursorBottom,n);
1961     }
1962 maya 3227 }
1963    
1964     void BuffRegionScrollUpNLines(int n) {
1965 maya 3393 int i;
1966     LONG SrcPtr, DestPtr;
1967 maya 3227
1968 maya 3393 if (n<1) {
1969     return;
1970     }
1971     UpdateStr();
1972 maya 3227
1973 maya 3393 if (n > 0) {
1974     if ((CursorTop == 0) && (CursorBottom == NumOfLines-1)) {
1975     WinOrgY = WinOrgY-n;
1976     BuffScroll(n,CursorBottom);
1977     DispCountScroll(n);
1978     }
1979     else if (CursorTop==0) {
1980     BuffScroll(n,CursorBottom);
1981     DispScrollNLines(WinOrgY,CursorBottom,n);
1982     }
1983     else {
1984     DestPtr = GetLinePtr(PageStart+CursorTop);
1985     if (n<CursorBottom-CursorTop+1) {
1986     SrcPtr = GetLinePtr(PageStart+CursorTop+n);
1987     for (i = CursorTop+n ; i<=CursorBottom ; i++) {
1988     memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
1989     memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
1990     memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
1991     memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
1992     memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
1993     SrcPtr = NextLinePtr(SrcPtr);
1994     DestPtr = NextLinePtr(DestPtr);
1995     }
1996     }
1997     else {
1998     n = CursorBottom-CursorTop+1;
1999     }
2000     for (i = CursorBottom+1-n ; i<=CursorBottom; i++) {
2001     memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
2002     memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
2003 doda 4070 memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
2004 maya 3393 memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
2005     memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
2006     DestPtr = NextLinePtr(DestPtr);
2007     }
2008     DispScrollNLines(CursorTop,CursorBottom,n);
2009     }
2010 maya 3227 }
2011     }
2012    
2013     void BuffRegionScrollDownNLines(int n) {
2014 maya 3393 int i;
2015     LONG SrcPtr, DestPtr;
2016 maya 3227
2017 maya 3393 if (n<1) {
2018     return;
2019     }
2020     UpdateStr();
2021 maya 3227
2022 maya 3393 DestPtr = GetLinePtr(PageStart+CursorBottom);
2023     if (n < CursorBottom-CursorTop+1) {
2024     SrcPtr = GetLinePtr(PageStart+CursorBottom-n);
2025     for (i=CursorBottom-n ; i>=CursorTop ; i--) {
2026     memmove(&(CodeBuff[DestPtr]),&(CodeBuff[SrcPtr]),NumOfColumns);
2027     memmove(&(AttrBuff[DestPtr]),&(AttrBuff[SrcPtr]),NumOfColumns);
2028     memmove(&(AttrBuff2[DestPtr]),&(AttrBuff2[SrcPtr]),NumOfColumns);
2029     memmove(&(AttrBuffFG[DestPtr]),&(AttrBuffFG[SrcPtr]),NumOfColumns);
2030     memmove(&(AttrBuffBG[DestPtr]),&(AttrBuffBG[SrcPtr]),NumOfColumns);
2031     SrcPtr = PrevLinePtr(SrcPtr);
2032     DestPtr = PrevLinePtr(DestPtr);
2033     }
2034     }
2035     else {
2036     n = CursorBottom - CursorTop + 1;
2037     }
2038     for (i = CursorTop+n-1; i>=CursorTop; i--) {
2039     memset(&(CodeBuff[DestPtr]),0x20,NumOfColumns);
2040     memset(&(AttrBuff[DestPtr]),AttrDefault,NumOfColumns);
2041 doda 4070 memset(&(AttrBuff2[DestPtr]),CurCharAttr.Attr2 & Attr2ColorMask, NumOfColumns);
2042 maya 3393 memset(&(AttrBuffFG[DestPtr]),CurCharAttr.Fore,NumOfColumns);
2043     memset(&(AttrBuffBG[DestPtr]),CurCharAttr.Back,NumOfColumns);
2044     DestPtr = PrevLinePtr(DestPtr);
2045     }
2046 maya 3227
2047 maya 3393 DispScrollNLines(CursorTop,CursorBottom,-n);
2048 maya 3227 }
2049    
2050     void BuffClearScreen()
2051     { // clear screen
2052 maya 3393 if ((StatusLine>0) && (CursorY==NumOfLines-1)) {
2053     BuffScrollNLines(1); /* clear status line */
2054     }
2055     else { /* clear main screen */
2056     UpdateStr();
2057     BuffScroll(NumOfLines-StatusLine,NumOfLines-1-StatusLine);
2058     DispScrollNLines(WinOrgY,NumOfLines-1-StatusLine,NumOfLines-StatusLine);
2059     }
2060 maya 3227 }
2061    
2062     void BuffUpdateScroll()
2063     // Updates scrolling
2064     {
2065 maya 3393 UpdateStr();
2066     DispUpdateScroll();
2067 maya 3227 }
2068    
2069     void CursorUpWithScroll()
2070     {
2071 maya 3393 if ((0<CursorY) && (CursorY<CursorTop) ||
2072     (CursorTop<CursorY)) {
2073     MoveCursor(CursorX,CursorY-1);
2074     }
2075     else if (CursorY==CursorTop) {
2076     ScrollUp1Line();
2077     }
2078 maya 3227 }
2079    
2080     // called by BuffDblClk
2081     // check if a character is the word delimiter
2082     BOOL IsDelimiter(LONG Line, int CharPtr)
2083     {
2084 maya 3393 if ((AttrBuff[Line+CharPtr] & AttrKanji) !=0) {
2085     return (ts.DelimDBCS!=0);
2086     }
2087     return (strchr(ts.DelimList,CodeBuff[Line+CharPtr])!=NULL);
2088 maya 3227 }
2089    
2090     void GetMinMax(int i1, int i2, int i3,
2091 maya 3393 int *min, int *max)
2092 maya 3227 {
2093 maya 3393 if (i1<i2) {
2094     *min = i1;
2095     *max = i2;
2096     }
2097     else {
2098     *min = i2;
2099     *max = i1;
2100     }
2101     if (i3<*min) {
2102     *min = i3;
2103     }
2104     if (i3>*max) {
2105     *max = i3;
2106     }
2107 maya 3227 }
2108    
2109     /* start - ishizaki */
2110     static void invokeBrowser(LONG ptr)
2111     {
2112     #ifdef URL_EMPHASIS
2113 maya 3393 LONG i, start, end;
2114 maya 4704 char url[1024], param[1024];
2115 maya 3227 char *uptr, ch;
2116    
2117 maya 3393 start = ptr;
2118     while (AttrBuff[start] & AttrURL) {
2119     start--;
2120     }
2121     start++;
2122 maya 3227
2123 maya 3393 end = ptr;
2124     while (AttrBuff[end] & AttrURL) {
2125     end++;
2126     }
2127     end--;
2128 maya 4704
2129 yutakapon 3405 if (start + (LONG)sizeof(url) <= end) {
2130     end = start + sizeof(url) - 1;
2131     end--; // '\0'の分は引いておく。
2132 maya 3393 }
2133 maya 3227 uptr = url;
2134 maya 3393 for (i = 0; i < end - start + 1; i++) {
2135 maya 3227 ch = CodeBuff[start + i];
2136     if ((start + i) % NumOfColumns == NumOfColumns - 1
2137     && ch == '\\') {
2138     // Emacs対応。行末に \ が来ている場合は、次の行に続くという意味で emacs が
2139     // 自動で挿入する文字なので、URLには含めないようにする。
2140     // (2007.8.7 yutaka)
2141    
2142     } else {
2143     *uptr++ = ch;
2144     }
2145 maya 3393 }
2146 maya 3227 *uptr = '\0';
2147 maya 4704
2148     if (strncmp(url, "http://", strlen("http://")) == 0 ||
2149     strncmp(url, "https://", strlen("https://")) == 0 ||
2150     strncmp(url, "ftp://", strlen("ftp://")) == 0) {
2151     if (strlen(ts.ClickableUrlBrowser) > 0) {
2152     _snprintf_s(param, sizeof(param), _TRUNCATE, "%s %s",
2153     ts.ClickableUrlBrowserArg, url);
2154     if ((int)ShellExecute(NULL, NULL, ts.ClickableUrlBrowser, param, NULL,SW_SHOWNORMAL) < 32) {
2155     // コマンドの実行に失敗した場合は通常と同じ処理をする
2156     ShellExecute(NULL, NULL, url, NULL, NULL,SW_SHOWNORMAL);
2157     }
2158     }
2159     else {
2160     ShellExecute(NULL, NULL, url, NULL, NULL,SW_SHOWNORMAL);
2161     }
2162     }
2163     else {
2164     ShellExecute(NULL, NULL, url, NULL, NULL,SW_SHOWNORMAL);
2165     }
2166 maya 3227 #endif
2167     }
2168     /* end - ishizaki */
2169    
2170     void ChangeSelectRegion()
2171     {
2172 maya 3393 POINT TempStart, TempEnd;
2173     int j, IStart, IEnd;
2174     BOOL Caret;
2175 maya 3227
2176 maya 3393 if ((SelectEndOld.x==SelectEnd.x) &&
2177     (SelectEndOld.y==SelectEnd.y)) {
2178     return;
2179     }
2180 maya 3227
2181 maya 3393 if (BoxSelect) {
2182     GetMinMax(SelectStart.x,SelectEndOld.x,SelectEnd.x,
2183     (int *)&TempStart.x,(int *)&TempEnd.x);
2184     GetMinMax(SelectStart.y,SelectEndOld.y,SelectEnd.y,
2185     (int *)&TempStart.y,(int *)&TempEnd.y);
2186     TempEnd.x--;
2187     Caret = IsCaretOn();
2188     if (Caret) {
2189     CaretOff();
2190     }
2191     DispInitDC();
2192     BuffUpdateRect(TempStart.x,TempStart.y-PageStart,
2193     TempEnd.x,TempEnd.y-PageStart);
2194     DispReleaseDC();
2195     if (Caret) {
2196     CaretOn();
2197     }
2198     SelectEndOld = SelectEnd;
2199     return;
2200     }
2201 maya 3227
2202 maya 3393 if ((SelectEndOld.y < SelectEnd.y) ||
2203     (SelectEndOld.y==SelectEnd.y) &&
2204     (SelectEndOld.x<=SelectEnd.x)) {
2205     TempStart = SelectEndOld;
2206     TempEnd.x