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

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