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 5259 - (hide annotations) (download) (as text)
Mon May 13 05:07:31 2013 UTC (10 years, 11 months ago) by doda
File MIME type: text/x-csrc
File size: 23249 byte(s)
マクロからのデータに対してはPasteDelayPerLineが働かないように修正。
http://sourceforge.jp/ticket/browse.php?group_id=1412&tid=31336

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    
567     static char *ClipboardPtr = NULL;
568     static int PasteCanceled = 0;
569    
570     static LRESULT CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
571     {
572     LOGFONT logfont;
573     HFONT font;
574     char uimsg[MAX_UIMSG];
575     //char *p;
576     POINT p;
577     RECT rc_dsk, rc_dlg;
578     int dlg_height, dlg_width;
579     OSVERSIONINFO osvi;
580 maya 3902 static int ok2right, edit2ok, edit2bottom;
581     RECT rc_edit, rc_ok, rc_cancel;
582 yutakapon 3635 // for status bar
583     static HWND hStatus = NULL;
584 maya 3641 static init_width, init_height;
585 maya 3227
586     switch (msg) {
587     case WM_INITDIALOG:
588     #if 0
589     for (p = ClipboardPtr; *p ; p++) {
590     char buf[20];
591     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%02x ", *p);
592     OutputDebugString(buf);
593     }
594     #endif
595    
596     font = (HFONT)SendMessage(hDlgWnd, WM_GETFONT, 0, 0);
597     GetObject(font, sizeof(LOGFONT), &logfont);
598     if (get_lang_font("DLG_TAHOMA_FONT", hDlgWnd, &logfont, &DlgClipboardFont, ts.UILanguageFile)) {
599     SendDlgItemMessage(hDlgWnd, IDC_EDIT, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
600     SendDlgItemMessage(hDlgWnd, IDOK, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
601     SendDlgItemMessage(hDlgWnd, IDCANCEL, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
602     }
603     else {
604     DlgClipboardFont = NULL;
605     }
606    
607     GetWindowText(hDlgWnd, uimsg, sizeof(uimsg));
608     get_lang_msg("DLG_CLIPBOARD_TITLE", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
609     SetWindowText(hDlgWnd, ts.UIMsg);
610     GetDlgItemText(hDlgWnd, IDCANCEL, uimsg, sizeof(uimsg));
611     get_lang_msg("BTN_CANCEL", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
612     SetDlgItemText(hDlgWnd, IDCANCEL, ts.UIMsg);
613     GetDlgItemText(hDlgWnd, IDOK, uimsg, sizeof(uimsg));
614     get_lang_msg("BTN_OK", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
615     SetDlgItemText(hDlgWnd, IDOK, ts.UIMsg);
616    
617     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_SETTEXT, 0, (LPARAM)ClipboardPtr);
618    
619     DispConvScreenToWin(CursorX, CursorY, &p.x, &p.y);
620     ClientToScreen(HVTWin, &p);
621    
622     // �L�����b�g���������������o���������������\���t����������
623     // �m�F�E�C���h�E�����������������\���������������������B
624     // �E�C���h�E���������o������������������ (2008.4.24 maya)
625     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
626     GetVersionEx(&osvi);
627 maya 3509 if ( (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 4) ||
628     (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && osvi.dwMinorVersion < 10) ) {
629     // NT4.0, 95 ���}���`���j�^API��������
630 maya 3227 SystemParametersInfo(SPI_GETWORKAREA, 0, &rc_dsk, 0);
631     }
632     else {
633     HMONITOR hm;
634     POINT pt;
635     MONITORINFO mi;
636    
637     pt.x = p.x;
638     pt.y = p.y;
639     hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
640    
641     mi.cbSize = sizeof(MONITORINFO);
642     GetMonitorInfo(hm, &mi);
643     rc_dsk = mi.rcWork;
644     }
645     GetWindowRect(hDlgWnd, &rc_dlg);
646     dlg_height = rc_dlg.bottom-rc_dlg.top;
647     dlg_width = rc_dlg.right-rc_dlg.left;
648     if (p.y < rc_dsk.top) {
649     p.y = rc_dsk.top;
650     }
651     else if (p.y + dlg_height > rc_dsk.bottom) {
652     p.y = rc_dsk.bottom - dlg_height;
653     }
654     if (p.x < rc_dsk.left) {
655     p.x = rc_dsk.left;
656     }
657     else if (p.x + dlg_width > rc_dsk.right) {
658     p.x = rc_dsk.right - dlg_width;
659     }
660    
661     SetWindowPos(hDlgWnd, NULL, p.x, p.y,
662     0, 0, SWP_NOSIZE | SWP_NOZORDER);
663    
664 maya 3641 // �_�C�A���O�������T�C�Y������
665     GetWindowRect(hDlgWnd, &rc_dlg);
666     init_width = rc_dlg.right - rc_dlg.left;
667     init_height = rc_dlg.bottom - rc_dlg.top;
668    
669 maya 3227 // �����T�C�Y�����K�v���l���v�Z
670     GetClientRect(hDlgWnd, &rc_dlg);
671     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
672     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
673    
674     p.x = rc_dlg.right;
675     p.y = rc_dlg.bottom;
676     ClientToScreen(hDlgWnd, &p);
677     ok2right = p.x - rc_ok.left;
678 maya 3902 edit2bottom = p.y - rc_edit.bottom;
679 maya 3227 edit2ok = rc_ok.left - rc_edit.right;
680    
681     // �T�C�Y������
682     SetWindowPos(hDlgWnd, NULL, 0, 0,
683     ts.PasteDialogSize.cx, ts.PasteDialogSize.cy,
684     SWP_NOZORDER | SWP_NOMOVE);
685    
686 yutakapon 3635 // ���T�C�Y�A�C�R�����E�����\���������������A�X�e�[�^�X�o�[���t�����B
687     InitCommonControls();
688     hStatus = CreateStatusWindow(
689     WS_CHILD | WS_VISIBLE |
690     CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hDlgWnd, 1);
691    
692 maya 3227 return TRUE;
693    
694     case WM_COMMAND:
695     switch (LOWORD(wp)) {
696     case IDOK:
697     {
698     int len = SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXTLENGTH, 0, 0);
699     HGLOBAL hMem;
700     char *buf;
701 maya 5071 int wide_len;
702     HGLOBAL wide_hMem;
703     LPWSTR wide_buf;
704 maya 3227
705 maya 3902 if (OpenClipboard(hDlgWnd) != 0) {
706     hMem = GlobalAlloc(GMEM_MOVEABLE, len + 1);
707     buf = GlobalLock(hMem);
708     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXT, len + 1, (LPARAM)buf);
709     GlobalUnlock(hMem);
710 maya 3227
711 maya 5071 wide_len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
712     wide_hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * wide_len);
713     if (wide_hMem) {
714     wide_buf = (LPWSTR)GlobalLock(wide_hMem);
715     MultiByteToWideChar(CP_ACP, 0, buf, -1, wide_buf, wide_len);
716     GlobalUnlock(wide_hMem);
717     }
718    
719 maya 3902 EmptyClipboard();
720     SetClipboardData(CF_TEXT, hMem);
721 maya 5071 if (wide_buf) {
722     SetClipboardData(CF_UNICODETEXT, wide_hMem);
723     }
724 maya 3902 CloseClipboard();
725     // hMem���N���b�v�{�[�h�������������������A�j�����������������B
726     }
727 maya 3227
728     if (DlgClipboardFont != NULL) {
729     DeleteObject(DlgClipboardFont);
730     }
731    
732 yutakapon 3635 DestroyWindow(hStatus);
733 maya 3227 EndDialog(hDlgWnd, IDOK);
734     }
735     break;
736    
737     case IDCANCEL:
738     PasteCanceled = 1;
739    
740     if (DlgClipboardFont != NULL) {
741     DeleteObject(DlgClipboardFont);
742     }
743    
744 yutakapon 3635 DestroyWindow(hStatus);
745 maya 3227 EndDialog(hDlgWnd, IDCANCEL);
746     break;
747    
748     default:
749     return FALSE;
750     }
751    
752     #if 0
753     case WM_CLOSE:
754     PasteCanceled = 1;
755     EndDialog(hDlgWnd, 0);
756     return TRUE;
757     #endif
758    
759     case WM_SIZE:
760     {
761     // ���z�u
762     POINT p;
763     int dlg_w, dlg_h;
764    
765     GetClientRect(hDlgWnd, &rc_dlg);
766     dlg_w = rc_dlg.right;
767     dlg_h = rc_dlg.bottom;
768    
769     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
770     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
771     GetWindowRect(GetDlgItem(hDlgWnd, IDCANCEL), &rc_cancel);
772    
773     // OK
774     p.x = rc_ok.left;
775     p.y = rc_ok.top;
776     ScreenToClient(hDlgWnd, &p);
777     SetWindowPos(GetDlgItem(hDlgWnd, IDOK), 0,
778     dlg_w - ok2right, p.y, 0, 0,
779     SWP_NOSIZE | SWP_NOZORDER);
780    
781     // CANCEL
782     p.x = rc_cancel.left;
783     p.y = rc_cancel.top;
784     ScreenToClient(hDlgWnd, &p);
785     SetWindowPos(GetDlgItem(hDlgWnd, IDCANCEL), 0,
786     dlg_w - ok2right, p.y, 0, 0,
787     SWP_NOSIZE | SWP_NOZORDER);
788    
789     // EDIT
790     p.x = rc_edit.left;
791     p.y = rc_edit.top;
792     ScreenToClient(hDlgWnd, &p);
793     SetWindowPos(GetDlgItem(hDlgWnd, IDC_EDIT), 0,
794 maya 3902 0, 0, dlg_w - p.x - edit2ok - ok2right, dlg_h - p.y - edit2bottom,
795 maya 3227 SWP_NOMOVE | SWP_NOZORDER);
796    
797     // �T�C�Y������
798     GetWindowRect(hDlgWnd, &rc_dlg);
799     ts.PasteDialogSize.cx = rc_dlg.right - rc_dlg.left;
800     ts.PasteDialogSize.cy = rc_dlg.bottom - rc_dlg.top;
801 yutakapon 3635
802     // status bar
803     SendMessage(hStatus , msg , wp , lp);
804 maya 3227 }
805     return TRUE;
806    
807 maya 3641 case WM_GETMINMAXINFO:
808     {
809     // �_�C�A���O�������T�C�Y����������������������������
810     LPMINMAXINFO lpmmi;
811     lpmmi = (LPMINMAXINFO)lp;
812     lpmmi->ptMinTrackSize.x = init_width;
813     lpmmi->ptMinTrackSize.y = init_height;
814     }
815     return FALSE;
816    
817 maya 3227 default:
818     return FALSE;
819     }
820     return TRUE;
821     }
822    
823 yutakapon 3535 // �t�@�C�������`���������������Atext���������������������B
824     static int search_clipboard(char *filename, char *text)
825     {
826     int ret = 0; // no hit
827     FILE *fp = NULL;
828     char buf[256];
829     int len;
830    
831     if (filename == NULL || filename[0] == '\0')
832     goto error;
833    
834     fp = fopen(filename, "r");
835     if (fp == NULL)
836     goto error;
837    
838     // TODO: ���s��256byte�������������������l��
839     while (fgets(buf, sizeof(buf), fp) != NULL) {
840     len = strlen(buf);
841     if (buf[len - 1] == '\n')
842     buf[len - 1] = '\0';
843     if (buf[0] == '\0')
844     continue;
845     if (strstr(text, buf)) { // hit
846     ret = 1;
847     break;
848     }
849     }
850    
851     error:
852     if (fp)
853     fclose(fp);
854    
855     return (ret);
856     }
857    
858    
859 maya 3227 //
860     // �N���b�v�{�[�h�����s�R�[�h�����������������A�m�F�_�C�A���O���\�������B
861     // �N���b�v�{�[�h�����X�����\�B
862     //
863     // return 0: Cancel
864     // 1: Paste OK
865     //
866     // (2008.2.3 yutaka)
867     //
868 doda 4260 int CBStartPasteConfirmChange(HWND HWin, BOOL AddCR)
869 maya 3227 {
870     UINT Cf;
871     HANDLE hText;
872     char *pText;
873     int pos;
874     int ret = 0;
875 doda 4273 BOOL confirm = FALSE;
876 maya 5071 HANDLE wide_hText;
877     LPWSTR wide_buf;
878     int mb_len;
879 maya 3227
880     if (ts.ConfirmChangePaste == 0)
881     return 1;
882    
883     if (! cv.Ready)
884     goto error;
885     if (TalkStatus!=IdTalkKeyb)
886     goto error;
887    
888 maya 5071 if (IsClipboardFormatAvailable(CF_UNICODETEXT))
889     Cf = CF_UNICODETEXT;
890     else if (IsClipboardFormatAvailable(CF_TEXT))
891 maya 3227 Cf = CF_TEXT;
892     else if (IsClipboardFormatAvailable(CF_OEMTEXT))
893     Cf = CF_OEMTEXT;
894     else
895     goto error;
896    
897     if (!OpenClipboard(HWin))
898     goto error;
899    
900 maya 5071 if (Cf == CF_UNICODETEXT) {
901     wide_hText = GetClipboardData(CF_UNICODETEXT);
902     if (wide_hText != NULL) {
903     wide_buf = GlobalLock(wide_hText);
904     mb_len = WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, NULL, 0, NULL, NULL);
905     ClipboardPtr = (char *)calloc(sizeof(char), mb_len);
906     WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, ClipboardPtr, mb_len, NULL, NULL);
907     GlobalUnlock(wide_hText);
908 doda 4273 }
909     else {
910 maya 5071 CloseClipboard();
911     goto error;
912 doda 4273 }
913 maya 5071 }
914     else {
915     hText = GetClipboardData(Cf);
916     if (hText != NULL) {
917     pText = (char *)GlobalLock(hText);
918 maya 3902 ClipboardPtr = (char *)calloc(sizeof(char), strlen(pText)+1);
919     memcpy(ClipboardPtr, pText, strlen(pText));
920     GlobalUnlock(hText);
921 maya 3227 }
922 maya 3902 else {
923     CloseClipboard();
924 maya 5071 goto error;
925 maya 3902 }
926 maya 5071 }
927     CloseClipboard();
928 maya 3227
929 maya 5071 if (AddCR) {
930     if (ts.ConfirmChangePasteCR) {
931     confirm = TRUE;
932     }
933     }
934     else {
935     pos = strcspn(ClipboardPtr, "\r\n"); // ���s����������������
936     if (ClipboardPtr[pos] != '\0' || AddCR) {
937     confirm = TRUE;
938     }
939     }
940 maya 3227
941 maya 5071 // �������T�[�`����
942     if (!confirm && search_clipboard(ts.ConfirmChangePasteStringFile, ClipboardPtr)) {
943     confirm = TRUE;
944 maya 3227 }
945    
946 maya 5071 if (confirm) {
947     PasteCanceled = 0;
948     ret = DialogBox(hInst, MAKEINTRESOURCE(IDD_CLIPBOARD_DIALOG),
949     HVTWin, (DLGPROC)OnClipboardDlgProc);
950     if (ret == 0 || ret == -1) {
951     ret = GetLastError();
952     }
953    
954     if (PasteCanceled) {
955     ret = 0;
956     goto error;
957     }
958     }
959    
960     ret = 1;
961    
962 maya 3227 error:
963 maya 5071 if (ClipboardPtr != NULL) {
964     free(ClipboardPtr);
965     ClipboardPtr = NULL;
966     }
967 maya 3227 return (ret);
968     }

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