Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/clipboar.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6435 - (hide annotations) (download) (as text)
Mon Jul 11 08:53:02 2016 UTC (7 years, 9 months ago) by doda
File MIME type: text/x-csrc
File size: 24162 byte(s)
・行末の空白/タブを削除
・インデント調整
1 maya 3227 /* Tera Term
2     Copyright(C) 1994-1998 T. Teranishi
3     All rights reserved. */
4    
5     /* TERATERM.EXE, Clipboard routines */
6     #include "teraterm.h"
7     #include "tttypes.h"
8     #include "vtdisp.h"
9     #include <string.h>
10     #include <stdlib.h>
11     #include <stdio.h>
12 yutakapon 3635 #include <commctrl.h>
13 maya 3227
14     #include "ttwinman.h"
15     #include "ttcommon.h"
16 doda 4769 #include "ttlib.h"
17 maya 3227
18     #include "clipboar.h"
19     #include "tt_res.h"
20    
21     // for clipboard copy
22     static HGLOBAL CBCopyHandle = NULL;
23     static PCHAR CBCopyPtr = NULL;
24 maya 5071 static HGLOBAL CBCopyWideHandle = NULL;
25     static LPWSTR CBCopyWidePtr = NULL;
26 maya 3227
27 doda 3872 #define CB_BRACKET_NONE 0
28     #define CB_BRACKET_START 1
29     #define CB_BRACKET_END 2
30 maya 3227 // for clipboard paste
31     static HGLOBAL CBMemHandle = NULL;
32     static PCHAR CBMemPtr = NULL;
33     static LONG CBMemPtr2 = 0;
34     static BOOL CBAddCR = FALSE;
35 doda 3896 static int CBBracketed = CB_BRACKET_NONE;
36 maya 3227 static BYTE CBByte;
37     static BOOL CBRetrySend;
38     static BOOL CBRetryEcho;
39     static BOOL CBSendCR;
40     static BOOL CBDDE;
41 maya 5071 static BOOL CBWIDE;
42 doda 3974 static BOOL CBEchoOnly;
43 doda 5259 static BOOL CBInsertDelay = FALSE;
44 maya 3227
45     static HFONT DlgClipboardFont;
46    
47     PCHAR CBOpen(LONG MemSize)
48     {
49 maya 3393 if (MemSize==0) {
50     return (NULL);
51     }
52     if (CBCopyHandle!=NULL) {
53     return (NULL);
54     }
55     CBCopyPtr = NULL;
56     CBCopyHandle = GlobalAlloc(GMEM_MOVEABLE, MemSize);
57     if (CBCopyHandle == NULL) {
58     MessageBeep(0);
59     }
60     else {
61     CBCopyPtr = GlobalLock(CBCopyHandle);
62     if (CBCopyPtr == NULL) {
63     GlobalFree(CBCopyHandle);
64     CBCopyHandle = NULL;
65     MessageBeep(0);
66     }
67     }
68     return (CBCopyPtr);
69 maya 3227 }
70    
71     void CBClose()
72     {
73 maya 3393 BOOL Empty;
74 maya 5071 int WideCharLength;
75    
76 maya 3393 if (CBCopyHandle==NULL) {
77     return;
78     }
79 maya 3227
80 maya 5071 WideCharLength = MultiByteToWideChar(CP_ACP, 0, CBCopyPtr, -1, NULL, 0);
81     CBCopyWideHandle = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * WideCharLength);
82     if (CBCopyWideHandle) {
83     CBCopyWidePtr = (LPWSTR)GlobalLock(CBCopyWideHandle);
84     MultiByteToWideChar(CP_ACP, 0, CBCopyPtr, -1, CBCopyWidePtr, WideCharLength);
85     GlobalUnlock(CBCopyWideHandle);
86     }
87    
88 maya 3393 Empty = FALSE;
89     if (CBCopyPtr!=NULL) {
90     Empty = (CBCopyPtr[0]==0);
91     }
92 maya 3227
93 maya 3393 GlobalUnlock(CBCopyHandle);
94     CBCopyPtr = NULL;
95 maya 3227
96 maya 3393 if (OpenClipboard(HVTWin)) {
97     EmptyClipboard();
98     if (! Empty) {
99     SetClipboardData(CF_TEXT, CBCopyHandle);
100 maya 5071 if (CBCopyWidePtr) {
101     SetClipboardData(CF_UNICODETEXT, CBCopyWideHandle);
102     CBCopyWidePtr = NULL;
103     }
104 maya 3393 }
105     CloseClipboard();
106     }
107     CBCopyHandle = NULL;
108 maya 5071 CBCopyWideHandle = NULL;
109 maya 3227 }
110    
111 doda 3872 void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed,
112 maya 3393 int BuffSize, PCHAR DataPtr, int DataSize)
113 maya 3227 //
114     // DataPtr and DataSize are used only for DDE
115     // For clipboard, BuffSize should be 0
116     // DataSize should be <= BuffSize
117     {
118 maya 3393 UINT Cf;
119 maya 3227
120 maya 3393 if (! cv.Ready) {
121     return;
122     }
123     if (TalkStatus!=IdTalkKeyb) {
124     return;
125     }
126 maya 3227
127 maya 3393 CBAddCR = AddCR;
128 doda 3872 if (Bracketed) {
129     CBBracketed = CB_BRACKET_START;
130     }
131 maya 3227
132 maya 3393 if (BuffSize==0) { // for clipboar
133 maya 5071 if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
134     Cf = CF_UNICODETEXT;
135     }
136     else if (IsClipboardFormatAvailable(CF_TEXT)) {
137 maya 3393 Cf = CF_TEXT;
138     }
139     else if (IsClipboardFormatAvailable(CF_OEMTEXT)) {
140     Cf = CF_OEMTEXT;
141     }
142     else {
143     return;
144     }
145     }
146 maya 3227
147 doda 3974 CBEchoOnly = FALSE;
148    
149 maya 3393 CBMemHandle = NULL;
150     CBMemPtr = NULL;
151     CBMemPtr2 = 0;
152     CBDDE = FALSE;
153 maya 5071 CBWIDE = FALSE;
154 doda 5259 CBInsertDelay = FALSE;
155    
156 maya 3393 if (BuffSize==0) { //clipboard
157 doda 5259 if (ts.PasteDelayPerLine > 0) {
158     CBInsertDelay = TRUE;
159     }
160 maya 3393 if (OpenClipboard(HWin)) {
161 maya 5071 if (Cf == CF_UNICODETEXT) {
162     // �\���t���������� CBMemHandle �������� dde ������������ CBMemPtr ���g������
163     HGLOBAL TmpHandle = GetClipboardData(Cf);
164     CBWIDE = TRUE;
165     if (TmpHandle) {
166     LPWSTR TmpPtr = (LPWSTR)GlobalLock(TmpHandle);
167     int mb_len = WideCharToMultiByte(CP_ACP, 0, TmpPtr, -1, 0, 0, NULL, NULL);
168    
169     CBMemHandle = GlobalAlloc(GHND, mb_len);
170     if (CBMemHandle != NULL) {
171     CBMemPtr = GlobalLock(CBMemHandle);
172     if (CBMemPtr != NULL) {
173     WideCharToMultiByte(CP_ACP, 0, TmpPtr, -1, CBMemPtr, mb_len, NULL, NULL);
174    
175     GlobalUnlock(CBMemHandle);
176     CBMemPtr=NULL;
177     TalkStatus=IdTalkCB;
178     }
179    
180     GlobalUnlock(TmpHandle);
181     CloseClipboard();
182     }
183     }
184     }
185     else {
186     CBMemHandle = GetClipboardData(Cf);
187     if (CBMemHandle!=NULL) {
188     TalkStatus=IdTalkCB;
189     }
190     }
191 maya 3393 }
192     }
193     else { // dde
194     CBMemHandle = GlobalAlloc(GHND,BuffSize);
195     if (CBMemHandle != NULL) {
196     CBDDE = TRUE;
197     CBMemPtr = GlobalLock(CBMemHandle);
198     if (CBMemPtr != NULL) {
199     memcpy(CBMemPtr,DataPtr,DataSize);
200     GlobalUnlock(CBMemHandle);
201     CBMemPtr=NULL;
202     TalkStatus=IdTalkCB;
203     }
204     }
205     }
206     CBRetrySend = FALSE;
207     CBRetryEcho = FALSE;
208     CBSendCR = FALSE;
209     if (TalkStatus != IdTalkCB) {
210     CBEndPaste();
211     }
212 maya 3227 }
213    
214 doda 4769 void CBStartPasteB64(HWND HWin, PCHAR header, PCHAR footer)
215     {
216     HANDLE tmpHandle = NULL;
217     char *tmpPtr = NULL;
218     int len, hlen, flen, blen;
219 maya 5071 UINT Cf;
220     LPWSTR tmpPtrWide = NULL;
221     int mb_len;
222 doda 4769
223     if (! cv.Ready) {
224     return;
225     }
226     if (TalkStatus!=IdTalkKeyb) {
227     return;
228     }
229    
230     CBEchoOnly = FALSE;
231    
232     CBMemHandle = NULL;
233     CBMemPtr = NULL;
234     CBMemPtr2 = 0;
235     CBDDE = TRUE;
236 maya 5071 CBWIDE = FALSE;
237 doda 4769
238 doda 5259 if (ts.PasteDelayPerLine > 0) {
239     CBInsertDelay = TRUE;
240     }
241     else {
242     CBInsertDelay = FALSE;
243     }
244    
245 maya 5071 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(HWin)) {
246     Cf = CF_UNICODETEXT;
247     if ((tmpHandle = GetClipboardData(CF_UNICODETEXT)) == NULL) {
248     CloseClipboard();
249     }
250     }
251     else if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(HWin)) {
252     Cf = CF_TEXT;
253 doda 4769 if ((tmpHandle = GetClipboardData(CF_TEXT)) == NULL) {
254     CloseClipboard();
255     }
256     }
257     else if (IsClipboardFormatAvailable(CF_OEMTEXT) && OpenClipboard(HWin)) {
258 maya 5071 Cf = CF_OEMTEXT;
259 doda 4769 if ((tmpHandle = GetClipboardData(CF_OEMTEXT)) == NULL) {
260     CloseClipboard();
261     }
262     }
263    
264 maya 5071 if (Cf == CF_UNICODETEXT) {
265     if (tmpHandle) {
266     if ((tmpPtrWide = GlobalLock(tmpHandle)) != NULL) {
267     hlen = strlen(header);
268     flen = strlen(footer);
269     mb_len = WideCharToMultiByte(CP_ACP, 0, tmpPtrWide, -1, 0, 0, NULL, NULL);
270     blen = (mb_len + 2) / 3 * 4 + hlen + flen + 1;
271     if ((CBMemHandle = GlobalAlloc(GHND, blen)) != NULL) {
272     if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
273     if (hlen > 0) {
274     strncpy_s(CBMemPtr, blen, header, _TRUNCATE);
275     }
276     tmpPtr = (char *)calloc(sizeof(char), mb_len);
277     WideCharToMultiByte(CP_ACP, 0, tmpPtrWide, -1, tmpPtr, mb_len, NULL, NULL);
278     b64encode(CBMemPtr + hlen, blen - hlen, tmpPtr, mb_len);
279     free(tmpPtr);
280     if (flen > 0) {
281     strncat_s(CBMemPtr, blen, footer, _TRUNCATE);
282     }
283     TalkStatus=IdTalkCB;
284     GlobalUnlock(CBMemPtr);
285     CBMemPtr = NULL;
286 doda 4769 }
287 maya 5071 }
288     GlobalUnlock(tmpPtrWide);
289     }
290     CloseClipboard();
291     }
292     }
293     else {
294     if (tmpHandle) {
295     if ((tmpPtr = GlobalLock(tmpHandle)) != NULL) {
296     hlen = strlen(header);
297     flen = strlen(footer);
298     len = strlen(tmpPtr);
299     blen = (len + 2) / 3 * 4 + hlen + flen + 1;
300     if ((CBMemHandle = GlobalAlloc(GHND, blen)) != NULL) {
301     if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
302     if (hlen > 0) {
303     strncpy_s(CBMemPtr, blen, header, _TRUNCATE);
304     }
305     b64encode(CBMemPtr + hlen, blen - hlen, tmpPtr, len);
306     if (flen > 0) {
307     strncat_s(CBMemPtr, blen, footer, _TRUNCATE);
308     }
309     TalkStatus=IdTalkCB;
310     GlobalUnlock(CBMemPtr);
311     CBMemPtr = NULL;
312 doda 4769 }
313     }
314 maya 5071 GlobalUnlock(tmpPtr);
315 doda 4769 }
316 maya 5071 CloseClipboard();
317 doda 4769 }
318     }
319    
320     CBRetrySend = FALSE;
321     CBRetryEcho = FALSE;
322     CBSendCR = FALSE;
323     if (TalkStatus != IdTalkCB) {
324     CBEndPaste();
325     }
326     }
327    
328 doda 3974 void CBStartEcho(PCHAR DataPtr, int DataSize)
329     {
330     if (! cv.Ready) {
331     return;
332     }
333     if (TalkStatus!=IdTalkKeyb) {
334     return;
335     }
336    
337     CBEchoOnly = TRUE;
338     CBMemPtr2 = 0;
339     CBRetryEcho = FALSE;
340     CBSendCR = FALSE;
341 maya 5071 CBWIDE = FALSE;
342 doda 3974
343 doda 4769 CBDDE = TRUE;
344 doda 3974 if ((CBMemHandle = GlobalAlloc(GHND, DataSize)) != NULL) {
345     if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
346     memcpy(CBMemPtr, DataPtr, DataSize);
347     GlobalUnlock(CBMemHandle);
348     CBMemPtr=NULL;
349     TalkStatus=IdTalkCB;
350     }
351     }
352    
353     if (TalkStatus != IdTalkCB) {
354     CBEndPaste();
355     }
356     }
357    
358 maya 3227 // �����������N���b�v�{�[�h������DDE�f�[�^���[�������������B
359     //
360     // CBMemHandle�n���h�����O���[�o�������������A�����������I�������������A
361     // �����N���b�v�{�[�h������DDE�f�[�^�������������������������i�j�����������\�������j�B
362     // �����A�f�[�^���� null-terminate �����������������O�����������������A�������f�[�^����
363     // �����������B
364     // (2006.11.6 yutaka)
365     void CBSend()
366     {
367 maya 3393 int c;
368     BOOL EndFlag;
369 doda 3688 static DWORD lastcr;
370 doda 3872 static char BracketStart[] = "\033[200~";
371     static char BracketEnd[] = "\033[201~";
372     static int BracketPtr = 0;
373 doda 3688 DWORD now;
374 maya 3227
375 maya 3393 if (CBMemHandle==NULL) {
376     return;
377     }
378 maya 3227
379 doda 3974 if (CBEchoOnly) {
380     CBEcho();
381     return;
382     }
383    
384 doda 5259 if (CBInsertDelay) {
385     now = GetTickCount();
386     if (now - lastcr < (DWORD)ts.PasteDelayPerLine) {
387     return;
388     }
389 doda 3688 }
390    
391 maya 3393 if (CBRetrySend) {
392     CBRetryEcho = (ts.LocalEcho>0);
393     c = CommTextOut(&cv,(PCHAR)&CBByte,1);
394     CBRetrySend = (c==0);
395     if (CBRetrySend) {
396     return;
397     }
398     }
399 maya 3227
400 maya 3393 if (CBRetryEcho) {
401     c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
402     CBRetryEcho = (c==0);
403     if (CBRetryEcho) {
404     return;
405     }
406     }
407 maya 3227
408 maya 4009 CBMemPtr = GlobalLock(CBMemHandle);
409     if (CBMemPtr==NULL) {
410 maya 3393 return;
411     }
412 maya 3227
413 maya 3393 do {
414     if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a)) {
415     CBMemPtr2++;
416     // added PasteDelayPerLine (2009.4.12 maya)
417 doda 5259 if (CBInsertDelay) {
418 doda 3690 lastcr = now;
419     CBSendCR = FALSE;
420     SetTimer(HVTWin, IdPasteDelayTimer, ts.PasteDelayPerLine, NULL);
421     break;
422     }
423 maya 3393 }
424    
425     EndFlag = (CBMemPtr[CBMemPtr2]==0);
426 doda 3872 if (CBBracketed == CB_BRACKET_START) {
427     CBByte = BracketStart[BracketPtr++];
428     if (BracketPtr >= sizeof(BracketStart) - 1) {
429     CBBracketed = CB_BRACKET_END;
430     BracketPtr = 0;
431     }
432     }
433     else if (! EndFlag) {
434 maya 3393 CBByte = CBMemPtr[CBMemPtr2];
435     CBMemPtr2++;
436 maya 3227 // Decoding characters which are encoded by MACRO
437     // to support NUL character sending
438     //
439     // [encoded character] --> [decoded character]
440     // 01 01 --> 00
441     // 01 02 --> 01
442 maya 3393 if (CBByte==0x01) { /* 0x01 from MACRO */
443     CBByte = CBMemPtr[CBMemPtr2];
444     CBMemPtr2++;
445     CBByte = CBByte - 1; // character just after 0x01
446     }
447     }
448     else if (CBAddCR) {
449     EndFlag = FALSE;
450     CBAddCR = FALSE;
451     CBByte = 0x0d;
452     }
453 doda 3872 else if (CBBracketed == CB_BRACKET_END) {
454     EndFlag = FALSE;
455     CBByte = BracketEnd[BracketPtr++];
456     if (BracketPtr >= sizeof(BracketEnd) - 1) {
457     CBBracketed = CB_BRACKET_NONE;
458     BracketPtr = 0;
459     }
460     }
461 maya 3393 else {
462     CBEndPaste();
463     return;
464     }
465 maya 3227
466 maya 3393 if (! EndFlag) {
467     c = CommTextOut(&cv,(PCHAR)&CBByte,1);
468     CBSendCR = (CBByte==0x0D);
469     CBRetrySend = (c==0);
470     if ((! CBRetrySend) &&
471     (ts.LocalEcho>0)) {
472     c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
473     CBRetryEcho = (c==0);
474     }
475     }
476     else {
477     c=0;
478     }
479     }
480     while (c>0);
481 maya 3227
482 maya 4009 if (CBMemPtr!=NULL) {
483 maya 3393 GlobalUnlock(CBMemHandle);
484     CBMemPtr=NULL;
485     }
486 maya 3227 }
487    
488 doda 3974 void CBEcho()
489     {
490     if (CBMemHandle==NULL) {
491     return;
492     }
493    
494     if (CBRetryEcho && CommTextEcho(&cv,(PCHAR)&CBByte,1) == 0) {
495     return;
496     }
497    
498     if ((CBMemPtr = GlobalLock(CBMemHandle)) == NULL) {
499     return;
500     }
501    
502     do {
503     if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a)) {
504     CBMemPtr2++;
505     }
506    
507     if (CBMemPtr[CBMemPtr2] == 0) {
508     CBRetryEcho = FALSE;
509     CBEndPaste();
510     return;
511     }
512    
513     CBByte = CBMemPtr[CBMemPtr2];
514     CBMemPtr2++;
515    
516     // Decoding characters which are encoded by MACRO
517     // to support NUL character sending
518     //
519     // [encoded character] --> [decoded character]
520     // 01 01 --> 00
521     // 01 02 --> 01
522     if (CBByte==0x01) { /* 0x01 from MACRO */
523     CBByte = CBMemPtr[CBMemPtr2];
524     CBMemPtr2++;
525     CBByte = CBByte - 1; // character just after 0x01
526     }
527    
528     CBSendCR = (CBByte==0x0D);
529    
530     } while (CommTextEcho(&cv,(PCHAR)&CBByte,1) > 0);
531    
532     CBRetryEcho = TRUE;
533    
534     if (CBMemHandle != NULL) {
535     GlobalUnlock(CBMemHandle);
536     CBMemPtr=NULL;
537     }
538     }
539    
540 maya 3227 void CBEndPaste()
541     {
542 maya 3393 TalkStatus = IdTalkKeyb;
543 maya 3227
544 maya 3393 if (CBMemHandle!=NULL) {
545     if (CBMemPtr!=NULL) {
546     GlobalUnlock(CBMemHandle);
547     }
548 maya 5071 if (CBDDE || CBWIDE) {
549 maya 3393 GlobalFree(CBMemHandle);
550     }
551     }
552 maya 5071 if (!CBDDE && !CBWIDE) {
553 maya 3393 CloseClipboard();
554     }
555 maya 3227
556 maya 3393 CBDDE = FALSE;
557 maya 5071 CBWIDE = FALSE;
558 maya 3393 CBMemHandle = NULL;
559     CBMemPtr = NULL;
560     CBMemPtr2 = 0;
561     CBAddCR = FALSE;
562 doda 3974 CBEchoOnly = FALSE;
563 doda 5259 CBInsertDelay = FALSE;
564 maya 3227 }
565    
566 doda 6418 BOOL CBSetClipboard(HWND owner, HGLOBAL hMem)
567     {
568     char *buf;
569     int wide_len;
570     HGLOBAL wide_hMem;
571     LPWSTR wide_buf;
572 maya 3227
573 doda 6418 if (OpenClipboard(owner) == 0)
574     return FALSE;
575    
576     buf = GlobalLock(hMem);
577    
578     wide_len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
579     wide_hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * wide_len);
580     if (wide_hMem) {
581     wide_buf = (LPWSTR)GlobalLock(wide_hMem);
582     MultiByteToWideChar(CP_ACP, 0, buf, -1, wide_buf, wide_len);
583     GlobalUnlock(wide_hMem);
584     }
585    
586     GlobalUnlock(hMem);
587    
588     EmptyClipboard();
589     SetClipboardData(CF_TEXT, hMem);
590     if (wide_buf) {
591     SetClipboardData(CF_UNICODETEXT, wide_hMem);
592     }
593     CloseClipboard();
594    
595     return TRUE;
596     }
597    
598     HGLOBAL CBAllocClipboardMem(char *text)
599     {
600     HGLOBAL hMem;
601     char *buf;
602     int len;
603    
604     len = strlen(text);
605    
606     hMem = GlobalAlloc(GMEM_MOVEABLE, len+1);
607     if (hMem) {
608     buf = GlobalLock(hMem);
609     strncpy_s(buf, len+1, text, _TRUNCATE);
610     GlobalUnlock(hMem);
611     }
612    
613     return hMem;
614     }
615    
616 maya 3227 static char *ClipboardPtr = NULL;
617     static int PasteCanceled = 0;
618    
619     static LRESULT CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
620     {
621     LOGFONT logfont;
622     HFONT font;
623     char uimsg[MAX_UIMSG];
624     //char *p;
625     POINT p;
626     RECT rc_dsk, rc_dlg;
627     int dlg_height, dlg_width;
628 maya 3902 static int ok2right, edit2ok, edit2bottom;
629     RECT rc_edit, rc_ok, rc_cancel;
630 yutakapon 3635 // for status bar
631     static HWND hStatus = NULL;
632 maya 3641 static init_width, init_height;
633 maya 3227
634     switch (msg) {
635     case WM_INITDIALOG:
636     #if 0
637     for (p = ClipboardPtr; *p ; p++) {
638     char buf[20];
639     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%02x ", *p);
640     OutputDebugString(buf);
641     }
642     #endif
643    
644     font = (HFONT)SendMessage(hDlgWnd, WM_GETFONT, 0, 0);
645     GetObject(font, sizeof(LOGFONT), &logfont);
646     if (get_lang_font("DLG_TAHOMA_FONT", hDlgWnd, &logfont, &DlgClipboardFont, ts.UILanguageFile)) {
647     SendDlgItemMessage(hDlgWnd, IDC_EDIT, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
648     SendDlgItemMessage(hDlgWnd, IDOK, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
649     SendDlgItemMessage(hDlgWnd, IDCANCEL, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
650     }
651     else {
652     DlgClipboardFont = NULL;
653     }
654    
655     GetWindowText(hDlgWnd, uimsg, sizeof(uimsg));
656     get_lang_msg("DLG_CLIPBOARD_TITLE", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
657     SetWindowText(hDlgWnd, ts.UIMsg);
658     GetDlgItemText(hDlgWnd, IDCANCEL, uimsg, sizeof(uimsg));
659     get_lang_msg("BTN_CANCEL", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
660     SetDlgItemText(hDlgWnd, IDCANCEL, ts.UIMsg);
661     GetDlgItemText(hDlgWnd, IDOK, uimsg, sizeof(uimsg));
662     get_lang_msg("BTN_OK", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
663     SetDlgItemText(hDlgWnd, IDOK, ts.UIMsg);
664    
665     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_SETTEXT, 0, (LPARAM)ClipboardPtr);
666    
667     DispConvScreenToWin(CursorX, CursorY, &p.x, &p.y);
668     ClientToScreen(HVTWin, &p);
669    
670     // �L�����b�g���������������o���������������\���t����������
671     // �m�F�E�C���h�E�����������������\���������������������B
672     // �E�C���h�E���������o������������������ (2008.4.24 maya)
673 yutakapon 6286 if (!HasMultiMonitorSupport()) {
674 maya 3509 // NT4.0, 95 ���}���`���j�^API��������
675 maya 3227 SystemParametersInfo(SPI_GETWORKAREA, 0, &rc_dsk, 0);
676     }
677     else {
678     HMONITOR hm;
679     POINT pt;
680     MONITORINFO mi;
681    
682     pt.x = p.x;
683     pt.y = p.y;
684     hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
685    
686     mi.cbSize = sizeof(MONITORINFO);
687     GetMonitorInfo(hm, &mi);
688     rc_dsk = mi.rcWork;
689     }
690     GetWindowRect(hDlgWnd, &rc_dlg);
691     dlg_height = rc_dlg.bottom-rc_dlg.top;
692     dlg_width = rc_dlg.right-rc_dlg.left;
693     if (p.y < rc_dsk.top) {
694     p.y = rc_dsk.top;
695     }
696     else if (p.y + dlg_height > rc_dsk.bottom) {
697     p.y = rc_dsk.bottom - dlg_height;
698     }
699     if (p.x < rc_dsk.left) {
700     p.x = rc_dsk.left;
701     }
702     else if (p.x + dlg_width > rc_dsk.right) {
703     p.x = rc_dsk.right - dlg_width;
704     }
705    
706     SetWindowPos(hDlgWnd, NULL, p.x, p.y,
707     0, 0, SWP_NOSIZE | SWP_NOZORDER);
708    
709 maya 3641 // �_�C�A���O�������T�C�Y������
710     GetWindowRect(hDlgWnd, &rc_dlg);
711     init_width = rc_dlg.right - rc_dlg.left;
712     init_height = rc_dlg.bottom - rc_dlg.top;
713    
714 maya 3227 // �����T�C�Y�����K�v���l���v�Z
715     GetClientRect(hDlgWnd, &rc_dlg);
716     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
717     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
718    
719     p.x = rc_dlg.right;
720     p.y = rc_dlg.bottom;
721     ClientToScreen(hDlgWnd, &p);
722     ok2right = p.x - rc_ok.left;
723 maya 3902 edit2bottom = p.y - rc_edit.bottom;
724 maya 3227 edit2ok = rc_ok.left - rc_edit.right;
725    
726     // �T�C�Y������
727     SetWindowPos(hDlgWnd, NULL, 0, 0,
728     ts.PasteDialogSize.cx, ts.PasteDialogSize.cy,
729     SWP_NOZORDER | SWP_NOMOVE);
730    
731 yutakapon 3635 // ���T�C�Y�A�C�R�����E�����\���������������A�X�e�[�^�X�o�[���t�����B
732     InitCommonControls();
733     hStatus = CreateStatusWindow(
734     WS_CHILD | WS_VISIBLE |
735     CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hDlgWnd, 1);
736    
737 maya 3227 return TRUE;
738    
739     case WM_COMMAND:
740     switch (LOWORD(wp)) {
741     case IDOK:
742     {
743     int len = SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXTLENGTH, 0, 0);
744     HGLOBAL hMem;
745     char *buf;
746    
747 doda 6418 hMem = GlobalAlloc(GMEM_MOVEABLE, len + 1);
748     if (hMem) {
749 maya 3902 buf = GlobalLock(hMem);
750     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXT, len + 1, (LPARAM)buf);
751 doda 6417 GlobalUnlock(hMem);
752    
753 doda 6418 if (! CBSetClipboard(hDlgWnd, hMem)) {
754     // �N���b�v�{�[�h�����Z�b�g�����s�������� hMem ���j������
755     // ���������������N���b�v�{�[�h�������������������A�j����������������
756     GlobalFree(hMem);
757 maya 5071 }
758 maya 3902 }
759 maya 3227
760     if (DlgClipboardFont != NULL) {
761     DeleteObject(DlgClipboardFont);
762     }
763    
764 yutakapon 3635 DestroyWindow(hStatus);
765 maya 3227 EndDialog(hDlgWnd, IDOK);
766     }
767     break;
768    
769     case IDCANCEL:
770     PasteCanceled = 1;
771    
772     if (DlgClipboardFont != NULL) {
773     DeleteObject(DlgClipboardFont);
774     }
775    
776 yutakapon 3635 DestroyWindow(hStatus);
777 maya 3227 EndDialog(hDlgWnd, IDCANCEL);
778     break;
779    
780     default:
781     return FALSE;
782     }
783    
784     #if 0
785     case WM_CLOSE:
786     PasteCanceled = 1;
787     EndDialog(hDlgWnd, 0);
788     return TRUE;
789     #endif
790    
791     case WM_SIZE:
792     {
793     // ���z�u
794     POINT p;
795     int dlg_w, dlg_h;
796    
797     GetClientRect(hDlgWnd, &rc_dlg);
798     dlg_w = rc_dlg.right;
799     dlg_h = rc_dlg.bottom;
800    
801     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
802     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
803     GetWindowRect(GetDlgItem(hDlgWnd, IDCANCEL), &rc_cancel);
804    
805     // OK
806     p.x = rc_ok.left;
807     p.y = rc_ok.top;
808     ScreenToClient(hDlgWnd, &p);
809     SetWindowPos(GetDlgItem(hDlgWnd, IDOK), 0,
810     dlg_w - ok2right, p.y, 0, 0,
811     SWP_NOSIZE | SWP_NOZORDER);
812    
813     // CANCEL
814     p.x = rc_cancel.left;
815     p.y = rc_cancel.top;
816     ScreenToClient(hDlgWnd, &p);
817     SetWindowPos(GetDlgItem(hDlgWnd, IDCANCEL), 0,
818     dlg_w - ok2right, p.y, 0, 0,
819     SWP_NOSIZE | SWP_NOZORDER);
820    
821     // EDIT
822     p.x = rc_edit.left;
823     p.y = rc_edit.top;
824     ScreenToClient(hDlgWnd, &p);
825     SetWindowPos(GetDlgItem(hDlgWnd, IDC_EDIT), 0,
826 maya 3902 0, 0, dlg_w - p.x - edit2ok - ok2right, dlg_h - p.y - edit2bottom,
827 maya 3227 SWP_NOMOVE | SWP_NOZORDER);
828    
829     // �T�C�Y������
830     GetWindowRect(hDlgWnd, &rc_dlg);
831     ts.PasteDialogSize.cx = rc_dlg.right - rc_dlg.left;
832     ts.PasteDialogSize.cy = rc_dlg.bottom - rc_dlg.top;
833 yutakapon 3635
834     // status bar
835     SendMessage(hStatus , msg , wp , lp);
836 maya 3227 }
837     return TRUE;
838    
839 maya 3641 case WM_GETMINMAXINFO:
840     {
841     // �_�C�A���O�������T�C�Y����������������������������
842     LPMINMAXINFO lpmmi;
843     lpmmi = (LPMINMAXINFO)lp;
844     lpmmi->ptMinTrackSize.x = init_width;
845     lpmmi->ptMinTrackSize.y = init_height;
846     }
847     return FALSE;
848    
849 maya 3227 default:
850     return FALSE;
851     }
852     return TRUE;
853     }
854    
855 yutakapon 3535 // �t�@�C�������`���������������Atext���������������������B
856     static int search_clipboard(char *filename, char *text)
857     {
858     int ret = 0; // no hit
859     FILE *fp = NULL;
860     char buf[256];
861     int len;
862 doda 6435
863 yutakapon 3535 if (filename == NULL || filename[0] == '\0')
864     goto error;
865    
866     fp = fopen(filename, "r");
867     if (fp == NULL)
868     goto error;
869    
870     // TODO: ���s��256byte�������������������l��
871     while (fgets(buf, sizeof(buf), fp) != NULL) {
872     len = strlen(buf);
873 doda 6435 if (buf[len - 1] == '\n')
874 yutakapon 3535 buf[len - 1] = '\0';
875     if (buf[0] == '\0')
876     continue;
877     if (strstr(text, buf)) { // hit
878     ret = 1;
879     break;
880     }
881     }
882    
883     error:
884     if (fp)
885     fclose(fp);
886    
887     return (ret);
888     }
889    
890    
891 maya 3227 //
892     // �N���b�v�{�[�h�����s�R�[�h�����������������A�m�F�_�C�A���O���\�������B
893     // �N���b�v�{�[�h�����X�����\�B
894     //
895     // return 0: Cancel
896     // 1: Paste OK
897     //
898     // (2008.2.3 yutaka)
899     //
900 doda 4260 int CBStartPasteConfirmChange(HWND HWin, BOOL AddCR)
901 maya 3227 {
902     UINT Cf;
903     HANDLE hText;
904 doda 6418 char *pText, *tail;
905 maya 3227 int pos;
906     int ret = 0;
907 doda 6418 BOOL confirm = FALSE, need_writeback = FALSE;
908 maya 5071 HANDLE wide_hText;
909     LPWSTR wide_buf;
910     int mb_len;
911 maya 3227
912 doda 6418 if (!ts.ConfirmChangePaste && !ts.TrimTrailingNLonPaste)
913 maya 3227 return 1;
914    
915 doda 6435 if (! cv.Ready)
916 maya 3227 goto error;
917     if (TalkStatus!=IdTalkKeyb)
918     goto error;
919    
920 maya 5071 if (IsClipboardFormatAvailable(CF_UNICODETEXT))
921     Cf = CF_UNICODETEXT;
922     else if (IsClipboardFormatAvailable(CF_TEXT))
923 maya 3227 Cf = CF_TEXT;
924     else if (IsClipboardFormatAvailable(CF_OEMTEXT))
925     Cf = CF_OEMTEXT;
926 doda 6435 else
927 maya 3227 goto error;
928    
929 doda 6435 if (!OpenClipboard(HWin))
930 maya 3227 goto error;
931    
932 maya 5071 if (Cf == CF_UNICODETEXT) {
933     wide_hText = GetClipboardData(CF_UNICODETEXT);
934     if (wide_hText != NULL) {
935     wide_buf = GlobalLock(wide_hText);
936     mb_len = WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, NULL, 0, NULL, NULL);
937     ClipboardPtr = (char *)calloc(sizeof(char), mb_len);
938     WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, ClipboardPtr, mb_len, NULL, NULL);
939     GlobalUnlock(wide_hText);
940 doda 4273 }
941     else {
942 maya 5071 CloseClipboard();
943     goto error;
944 doda 4273 }
945 maya 5071 }
946     else {
947     hText = GetClipboardData(Cf);
948     if (hText != NULL) {
949     pText = (char *)GlobalLock(hText);
950 maya 3902 ClipboardPtr = (char *)calloc(sizeof(char), strlen(pText)+1);
951     memcpy(ClipboardPtr, pText, strlen(pText));
952     GlobalUnlock(hText);
953 maya 3227 }
954 maya 3902 else {
955     CloseClipboard();
956 maya 5071 goto error;
957 maya 3902 }
958 maya 5071 }
959     CloseClipboard();
960 maya 3227
961 doda 6418 if (ts.TrimTrailingNLonPaste) {
962     for (tail=ClipboardPtr+strlen(ClipboardPtr)-1; tail >= ClipboardPtr; tail--) {
963     if (*tail == '\r' || *tail == '\n') {
964     *tail = '\0';
965     need_writeback = TRUE;
966     }
967     else {
968     break;
969     }
970     }
971     }
972    
973 maya 5071 if (AddCR) {
974     if (ts.ConfirmChangePasteCR) {
975     confirm = TRUE;
976     }
977     }
978     else {
979     pos = strcspn(ClipboardPtr, "\r\n"); // ���s����������������
980     if (ClipboardPtr[pos] != '\0' || AddCR) {
981     confirm = TRUE;
982     }
983     }
984 maya 3227
985 maya 5071 // �������T�[�`����
986     if (!confirm && search_clipboard(ts.ConfirmChangePasteStringFile, ClipboardPtr)) {
987     confirm = TRUE;
988 maya 3227 }
989    
990 maya 5071 if (confirm) {
991     PasteCanceled = 0;
992     ret = DialogBox(hInst, MAKEINTRESOURCE(IDD_CLIPBOARD_DIALOG),
993     HVTWin, (DLGPROC)OnClipboardDlgProc);
994     if (ret == 0 || ret == -1) {
995     ret = GetLastError();
996     }
997    
998     if (PasteCanceled) {
999     ret = 0;
1000     goto error;
1001     }
1002     }
1003 doda 6418 else if (need_writeback) {
1004     HGLOBAL hMem;
1005     hMem = CBAllocClipboardMem(ClipboardPtr);
1006     if (hMem) {
1007     if (! CBSetClipboard(NULL, hMem)) {
1008     // �N���b�v�{�[�h�����Z�b�g�����s�������� hMem ���j������
1009     // ���������������N���b�v�{�[�h�������������������A�j����������������
1010     GlobalFree(hMem);
1011     }
1012     }
1013     }
1014 maya 5071
1015     ret = 1;
1016    
1017 maya 3227 error:
1018 maya 5071 if (ClipboardPtr != NULL) {
1019     free(ClipboardPtr);
1020     ClipboardPtr = NULL;
1021     }
1022 maya 3227 return (ret);
1023     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26