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 6286 - (hide annotations) (download) (as text)
Mon Feb 1 15:14:14 2016 UTC (8 years, 2 months ago) by yutakapon
File MIME type: text/x-csrc
File size: 23009 byte(s)
チケット #35744 VS2015の警告除去

下記ブランチからマージした。
svn+ssh://yutakapon@svn.sourceforge.jp/svnroot/ttssh2/branches/vs2015_warn
リビジョン6194 - 6260

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

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