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 5071 - (hide annotations) (download) (as text)
Thu Nov 22 03:35:18 2012 UTC (11 years, 4 months ago) by maya
File MIME type: text/x-csrc
File size: 22971 byte(s)
クリップボードへのコピー・貼り付けで CF_UNICODETEXT も処理するようにした。
  キーボードレイアウトによっては CF_TEXT が文字化けした状態になるため。
  WideCharToMultiByte, MultiByteToWideChar で CP_ACP を利用しており、Windowsの「Unicode対応でないプログラムの言語」の設定によっては変換で文字化けする。
  ticket #30015
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 maya 3227
44     static HFONT DlgClipboardFont;
45    
46     PCHAR CBOpen(LONG MemSize)
47     {
48 maya 3393 if (MemSize==0) {
49     return (NULL);
50     }
51     if (CBCopyHandle!=NULL) {
52     return (NULL);
53     }
54     CBCopyPtr = NULL;
55     CBCopyHandle = GlobalAlloc(GMEM_MOVEABLE, MemSize);
56     if (CBCopyHandle == NULL) {
57     MessageBeep(0);
58     }
59     else {
60     CBCopyPtr = GlobalLock(CBCopyHandle);
61     if (CBCopyPtr == NULL) {
62     GlobalFree(CBCopyHandle);
63     CBCopyHandle = NULL;
64     MessageBeep(0);
65     }
66     }
67     return (CBCopyPtr);
68 maya 3227 }
69    
70     void CBClose()
71     {
72 maya 3393 BOOL Empty;
73 maya 5071 int WideCharLength;
74    
75 maya 3393 if (CBCopyHandle==NULL) {
76     return;
77     }
78 maya 3227
79 maya 5071 WideCharLength = MultiByteToWideChar(CP_ACP, 0, CBCopyPtr, -1, NULL, 0);
80     CBCopyWideHandle = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * WideCharLength);
81     if (CBCopyWideHandle) {
82     CBCopyWidePtr = (LPWSTR)GlobalLock(CBCopyWideHandle);
83     MultiByteToWideChar(CP_ACP, 0, CBCopyPtr, -1, CBCopyWidePtr, WideCharLength);
84     GlobalUnlock(CBCopyWideHandle);
85     }
86    
87 maya 3393 Empty = FALSE;
88     if (CBCopyPtr!=NULL) {
89     Empty = (CBCopyPtr[0]==0);
90     }
91 maya 3227
92 maya 3393 GlobalUnlock(CBCopyHandle);
93     CBCopyPtr = NULL;
94 maya 3227
95 maya 3393 if (OpenClipboard(HVTWin)) {
96     EmptyClipboard();
97     if (! Empty) {
98     SetClipboardData(CF_TEXT, CBCopyHandle);
99 maya 5071 if (CBCopyWidePtr) {
100     SetClipboardData(CF_UNICODETEXT, CBCopyWideHandle);
101     CBCopyWidePtr = NULL;
102     }
103 maya 3393 }
104     CloseClipboard();
105     }
106     CBCopyHandle = NULL;
107 maya 5071 CBCopyWideHandle = NULL;
108 maya 3227 }
109    
110 doda 3872 void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed,
111 maya 3393 int BuffSize, PCHAR DataPtr, int DataSize)
112 maya 3227 //
113     // DataPtr and DataSize are used only for DDE
114     // For clipboard, BuffSize should be 0
115     // DataSize should be <= BuffSize
116     {
117 maya 3393 UINT Cf;
118 maya 3227
119 maya 3393 if (! cv.Ready) {
120     return;
121     }
122     if (TalkStatus!=IdTalkKeyb) {
123     return;
124     }
125 maya 3227
126 maya 3393 CBAddCR = AddCR;
127 doda 3872 if (Bracketed) {
128     CBBracketed = CB_BRACKET_START;
129     }
130 maya 3227
131 maya 3393 if (BuffSize==0) { // for clipboar
132 maya 5071 if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
133     Cf = CF_UNICODETEXT;
134     }
135     else if (IsClipboardFormatAvailable(CF_TEXT)) {
136 maya 3393 Cf = CF_TEXT;
137     }
138     else if (IsClipboardFormatAvailable(CF_OEMTEXT)) {
139     Cf = CF_OEMTEXT;
140     }
141     else {
142     return;
143     }
144     }
145 maya 3227
146 doda 3974 CBEchoOnly = FALSE;
147    
148 maya 3393 CBMemHandle = NULL;
149     CBMemPtr = NULL;
150     CBMemPtr2 = 0;
151     CBDDE = FALSE;
152 maya 5071 CBWIDE = FALSE;
153 maya 3393 if (BuffSize==0) { //clipboard
154     if (OpenClipboard(HWin)) {
155 maya 5071 if (Cf == CF_UNICODETEXT) {
156     // �\���t���������� CBMemHandle �������� dde ������������ CBMemPtr ���g������
157     HGLOBAL TmpHandle = GetClipboardData(Cf);
158     CBWIDE = TRUE;
159     if (TmpHandle) {
160     LPWSTR TmpPtr = (LPWSTR)GlobalLock(TmpHandle);
161     int mb_len = WideCharToMultiByte(CP_ACP, 0, TmpPtr, -1, 0, 0, NULL, NULL);
162    
163     CBMemHandle = GlobalAlloc(GHND, mb_len);
164     if (CBMemHandle != NULL) {
165     CBMemPtr = GlobalLock(CBMemHandle);
166     if (CBMemPtr != NULL) {
167     WideCharToMultiByte(CP_ACP, 0, TmpPtr, -1, CBMemPtr, mb_len, NULL, NULL);
168    
169     GlobalUnlock(CBMemHandle);
170     CBMemPtr=NULL;
171     TalkStatus=IdTalkCB;
172     }
173    
174     GlobalUnlock(TmpHandle);
175     CloseClipboard();
176     }
177     }
178     }
179     else {
180     CBMemHandle = GetClipboardData(Cf);
181     if (CBMemHandle!=NULL) {
182     TalkStatus=IdTalkCB;
183     }
184     }
185 maya 3393 }
186     }
187     else { // dde
188     CBMemHandle = GlobalAlloc(GHND,BuffSize);
189     if (CBMemHandle != NULL) {
190     CBDDE = TRUE;
191     CBMemPtr = GlobalLock(CBMemHandle);
192     if (CBMemPtr != NULL) {
193     memcpy(CBMemPtr,DataPtr,DataSize);
194     GlobalUnlock(CBMemHandle);
195     CBMemPtr=NULL;
196     TalkStatus=IdTalkCB;
197     }
198     }
199     }
200     CBRetrySend = FALSE;
201     CBRetryEcho = FALSE;
202     CBSendCR = FALSE;
203     if (TalkStatus != IdTalkCB) {
204     CBEndPaste();
205     }
206 maya 3227 }
207    
208 doda 4769 void CBStartPasteB64(HWND HWin, PCHAR header, PCHAR footer)
209     {
210     HANDLE tmpHandle = NULL;
211     char *tmpPtr = NULL;
212     int len, hlen, flen, blen;
213 maya 5071 UINT Cf;
214     LPWSTR tmpPtrWide = NULL;
215     int mb_len;
216 doda 4769
217     if (! cv.Ready) {
218     return;
219     }
220     if (TalkStatus!=IdTalkKeyb) {
221     return;
222     }
223    
224     CBEchoOnly = FALSE;
225    
226     CBMemHandle = NULL;
227     CBMemPtr = NULL;
228     CBMemPtr2 = 0;
229     CBDDE = TRUE;
230 maya 5071 CBWIDE = FALSE;
231 doda 4769
232 maya 5071 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(HWin)) {
233     Cf = CF_UNICODETEXT;
234     if ((tmpHandle = GetClipboardData(CF_UNICODETEXT)) == NULL) {
235     CloseClipboard();
236     }
237     }
238     else if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(HWin)) {
239     Cf = CF_TEXT;
240 doda 4769 if ((tmpHandle = GetClipboardData(CF_TEXT)) == NULL) {
241     CloseClipboard();
242     }
243     }
244     else if (IsClipboardFormatAvailable(CF_OEMTEXT) && OpenClipboard(HWin)) {
245 maya 5071 Cf = CF_OEMTEXT;
246 doda 4769 if ((tmpHandle = GetClipboardData(CF_OEMTEXT)) == NULL) {
247     CloseClipboard();
248     }
249     }
250    
251 maya 5071 if (Cf == CF_UNICODETEXT) {
252     if (tmpHandle) {
253     if ((tmpPtrWide = GlobalLock(tmpHandle)) != NULL) {
254     hlen = strlen(header);
255     flen = strlen(footer);
256     mb_len = WideCharToMultiByte(CP_ACP, 0, tmpPtrWide, -1, 0, 0, NULL, NULL);
257     blen = (mb_len + 2) / 3 * 4 + hlen + flen + 1;
258     if ((CBMemHandle = GlobalAlloc(GHND, blen)) != NULL) {
259     if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
260     if (hlen > 0) {
261     strncpy_s(CBMemPtr, blen, header, _TRUNCATE);
262     }
263     tmpPtr = (char *)calloc(sizeof(char), mb_len);
264     WideCharToMultiByte(CP_ACP, 0, tmpPtrWide, -1, tmpPtr, mb_len, NULL, NULL);
265     b64encode(CBMemPtr + hlen, blen - hlen, tmpPtr, mb_len);
266     free(tmpPtr);
267     if (flen > 0) {
268     strncat_s(CBMemPtr, blen, footer, _TRUNCATE);
269     }
270     TalkStatus=IdTalkCB;
271     GlobalUnlock(CBMemPtr);
272     CBMemPtr = NULL;
273 doda 4769 }
274 maya 5071 }
275     GlobalUnlock(tmpPtrWide);
276     }
277     CloseClipboard();
278     }
279     }
280     else {
281     if (tmpHandle) {
282     if ((tmpPtr = GlobalLock(tmpHandle)) != NULL) {
283     hlen = strlen(header);
284     flen = strlen(footer);
285     len = strlen(tmpPtr);
286     blen = (len + 2) / 3 * 4 + hlen + flen + 1;
287     if ((CBMemHandle = GlobalAlloc(GHND, blen)) != NULL) {
288     if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
289     if (hlen > 0) {
290     strncpy_s(CBMemPtr, blen, header, _TRUNCATE);
291     }
292     b64encode(CBMemPtr + hlen, blen - hlen, tmpPtr, len);
293     if (flen > 0) {
294     strncat_s(CBMemPtr, blen, footer, _TRUNCATE);
295     }
296     TalkStatus=IdTalkCB;
297     GlobalUnlock(CBMemPtr);
298     CBMemPtr = NULL;
299 doda 4769 }
300     }
301 maya 5071 GlobalUnlock(tmpPtr);
302 doda 4769 }
303 maya 5071 CloseClipboard();
304 doda 4769 }
305     }
306    
307     CBRetrySend = FALSE;
308     CBRetryEcho = FALSE;
309     CBSendCR = FALSE;
310     if (TalkStatus != IdTalkCB) {
311     CBEndPaste();
312     }
313     }
314    
315 doda 3974 void CBStartEcho(PCHAR DataPtr, int DataSize)
316     {
317     if (! cv.Ready) {
318     return;
319     }
320     if (TalkStatus!=IdTalkKeyb) {
321     return;
322     }
323    
324     CBEchoOnly = TRUE;
325     CBMemPtr2 = 0;
326     CBRetryEcho = FALSE;
327     CBSendCR = FALSE;
328 maya 5071 CBWIDE = FALSE;
329 doda 3974
330 doda 4769 CBDDE = TRUE;
331 doda 3974 if ((CBMemHandle = GlobalAlloc(GHND, DataSize)) != NULL) {
332     if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
333     memcpy(CBMemPtr, DataPtr, DataSize);
334     GlobalUnlock(CBMemHandle);
335     CBMemPtr=NULL;
336     TalkStatus=IdTalkCB;
337     }
338     }
339    
340     if (TalkStatus != IdTalkCB) {
341     CBEndPaste();
342     }
343     }
344    
345 maya 3227 // �����������N���b�v�{�[�h������DDE�f�[�^���[�������������B
346     //
347     // CBMemHandle�n���h�����O���[�o�������������A�����������I�������������A
348     // �����N���b�v�{�[�h������DDE�f�[�^�������������������������i�j�����������\�������j�B
349     // �����A�f�[�^���� null-terminate �����������������O�����������������A�������f�[�^����
350     // �����������B
351     // (2006.11.6 yutaka)
352     void CBSend()
353     {
354 maya 3393 int c;
355     BOOL EndFlag;
356 doda 3688 static DWORD lastcr;
357 doda 3872 static char BracketStart[] = "\033[200~";
358     static char BracketEnd[] = "\033[201~";
359     static int BracketPtr = 0;
360 doda 3688 DWORD now;
361 maya 3227
362 maya 3393 if (CBMemHandle==NULL) {
363     return;
364     }
365 maya 3227
366 doda 3974 if (CBEchoOnly) {
367     CBEcho();
368     return;
369     }
370    
371 doda 3688 now = GetTickCount();
372 doda 3691 if (now - lastcr < (DWORD)ts.PasteDelayPerLine) {
373 doda 3688 return;
374     }
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 3690 if (ts.PasteDelayPerLine > 0) {
403     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 maya 3227 }
549    
550    
551     static char *ClipboardPtr = NULL;
552     static int PasteCanceled = 0;
553    
554     static LRESULT CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
555     {
556     LOGFONT logfont;
557     HFONT font;
558     char uimsg[MAX_UIMSG];
559     //char *p;
560     POINT p;
561     RECT rc_dsk, rc_dlg;
562     int dlg_height, dlg_width;
563     OSVERSIONINFO osvi;
564 maya 3902 static int ok2right, edit2ok, edit2bottom;
565     RECT rc_edit, rc_ok, rc_cancel;
566 yutakapon 3635 // for status bar
567     static HWND hStatus = NULL;
568 maya 3641 static init_width, init_height;
569 maya 3227
570     switch (msg) {
571     case WM_INITDIALOG:
572     #if 0
573     for (p = ClipboardPtr; *p ; p++) {
574     char buf[20];
575     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%02x ", *p);
576     OutputDebugString(buf);
577     }
578     #endif
579    
580     font = (HFONT)SendMessage(hDlgWnd, WM_GETFONT, 0, 0);
581     GetObject(font, sizeof(LOGFONT), &logfont);
582     if (get_lang_font("DLG_TAHOMA_FONT", hDlgWnd, &logfont, &DlgClipboardFont, ts.UILanguageFile)) {
583     SendDlgItemMessage(hDlgWnd, IDC_EDIT, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
584     SendDlgItemMessage(hDlgWnd, IDOK, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
585     SendDlgItemMessage(hDlgWnd, IDCANCEL, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
586     }
587     else {
588     DlgClipboardFont = NULL;
589     }
590    
591     GetWindowText(hDlgWnd, uimsg, sizeof(uimsg));
592     get_lang_msg("DLG_CLIPBOARD_TITLE", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
593     SetWindowText(hDlgWnd, ts.UIMsg);
594     GetDlgItemText(hDlgWnd, IDCANCEL, uimsg, sizeof(uimsg));
595     get_lang_msg("BTN_CANCEL", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
596     SetDlgItemText(hDlgWnd, IDCANCEL, ts.UIMsg);
597     GetDlgItemText(hDlgWnd, IDOK, uimsg, sizeof(uimsg));
598     get_lang_msg("BTN_OK", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
599     SetDlgItemText(hDlgWnd, IDOK, ts.UIMsg);
600    
601     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_SETTEXT, 0, (LPARAM)ClipboardPtr);
602    
603     DispConvScreenToWin(CursorX, CursorY, &p.x, &p.y);
604     ClientToScreen(HVTWin, &p);
605    
606     // �L�����b�g���������������o���������������\���t����������
607     // �m�F�E�C���h�E�����������������\���������������������B
608     // �E�C���h�E���������o������������������ (2008.4.24 maya)
609     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
610     GetVersionEx(&osvi);
611 maya 3509 if ( (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 4) ||
612     (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && osvi.dwMinorVersion < 10) ) {
613     // NT4.0, 95 ���}���`���j�^API��������
614 maya 3227 SystemParametersInfo(SPI_GETWORKAREA, 0, &rc_dsk, 0);
615     }
616     else {
617     HMONITOR hm;
618     POINT pt;
619     MONITORINFO mi;
620    
621     pt.x = p.x;
622     pt.y = p.y;
623     hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
624    
625     mi.cbSize = sizeof(MONITORINFO);
626     GetMonitorInfo(hm, &mi);
627     rc_dsk = mi.rcWork;
628     }
629     GetWindowRect(hDlgWnd, &rc_dlg);
630     dlg_height = rc_dlg.bottom-rc_dlg.top;
631     dlg_width = rc_dlg.right-rc_dlg.left;
632     if (p.y < rc_dsk.top) {
633     p.y = rc_dsk.top;
634     }
635     else if (p.y + dlg_height > rc_dsk.bottom) {
636     p.y = rc_dsk.bottom - dlg_height;
637     }
638     if (p.x < rc_dsk.left) {
639     p.x = rc_dsk.left;
640     }
641     else if (p.x + dlg_width > rc_dsk.right) {
642     p.x = rc_dsk.right - dlg_width;
643     }
644    
645     SetWindowPos(hDlgWnd, NULL, p.x, p.y,
646     0, 0, SWP_NOSIZE | SWP_NOZORDER);
647    
648 maya 3641 // �_�C�A���O�������T�C�Y������
649     GetWindowRect(hDlgWnd, &rc_dlg);
650     init_width = rc_dlg.right - rc_dlg.left;
651     init_height = rc_dlg.bottom - rc_dlg.top;
652    
653 maya 3227 // �����T�C�Y�����K�v���l���v�Z
654     GetClientRect(hDlgWnd, &rc_dlg);
655     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
656     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
657    
658     p.x = rc_dlg.right;
659     p.y = rc_dlg.bottom;
660     ClientToScreen(hDlgWnd, &p);
661     ok2right = p.x - rc_ok.left;
662 maya 3902 edit2bottom = p.y - rc_edit.bottom;
663 maya 3227 edit2ok = rc_ok.left - rc_edit.right;
664    
665     // �T�C�Y������
666     SetWindowPos(hDlgWnd, NULL, 0, 0,
667     ts.PasteDialogSize.cx, ts.PasteDialogSize.cy,
668     SWP_NOZORDER | SWP_NOMOVE);
669    
670 yutakapon 3635 // ���T�C�Y�A�C�R�����E�����\���������������A�X�e�[�^�X�o�[���t�����B
671     InitCommonControls();
672     hStatus = CreateStatusWindow(
673     WS_CHILD | WS_VISIBLE |
674     CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hDlgWnd, 1);
675    
676 maya 3227 return TRUE;
677    
678     case WM_COMMAND:
679     switch (LOWORD(wp)) {
680     case IDOK:
681     {
682     int len = SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXTLENGTH, 0, 0);
683     HGLOBAL hMem;
684     char *buf;
685 maya 5071 int wide_len;
686     HGLOBAL wide_hMem;
687     LPWSTR wide_buf;
688 maya 3227
689 maya 3902 if (OpenClipboard(hDlgWnd) != 0) {
690     hMem = GlobalAlloc(GMEM_MOVEABLE, len + 1);
691     buf = GlobalLock(hMem);
692     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXT, len + 1, (LPARAM)buf);
693     GlobalUnlock(hMem);
694 maya 3227
695 maya 5071 wide_len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
696     wide_hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * wide_len);
697     if (wide_hMem) {
698     wide_buf = (LPWSTR)GlobalLock(wide_hMem);
699     MultiByteToWideChar(CP_ACP, 0, buf, -1, wide_buf, wide_len);
700     GlobalUnlock(wide_hMem);
701     }
702    
703 maya 3902 EmptyClipboard();
704     SetClipboardData(CF_TEXT, hMem);
705 maya 5071 if (wide_buf) {
706     SetClipboardData(CF_UNICODETEXT, wide_hMem);
707     }
708 maya 3902 CloseClipboard();
709     // hMem���N���b�v�{�[�h�������������������A�j�����������������B
710     }
711 maya 3227
712     if (DlgClipboardFont != NULL) {
713     DeleteObject(DlgClipboardFont);
714     }
715    
716 yutakapon 3635 DestroyWindow(hStatus);
717 maya 3227 EndDialog(hDlgWnd, IDOK);
718     }
719     break;
720    
721     case IDCANCEL:
722     PasteCanceled = 1;
723    
724     if (DlgClipboardFont != NULL) {
725     DeleteObject(DlgClipboardFont);
726     }
727    
728 yutakapon 3635 DestroyWindow(hStatus);
729 maya 3227 EndDialog(hDlgWnd, IDCANCEL);
730     break;
731    
732     default:
733     return FALSE;
734     }
735    
736     #if 0
737     case WM_CLOSE:
738     PasteCanceled = 1;
739     EndDialog(hDlgWnd, 0);
740     return TRUE;
741     #endif
742    
743     case WM_SIZE:
744     {
745     // ���z�u
746     POINT p;
747     int dlg_w, dlg_h;
748    
749     GetClientRect(hDlgWnd, &rc_dlg);
750     dlg_w = rc_dlg.right;
751     dlg_h = rc_dlg.bottom;
752    
753     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
754     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
755     GetWindowRect(GetDlgItem(hDlgWnd, IDCANCEL), &rc_cancel);
756    
757     // OK
758     p.x = rc_ok.left;
759     p.y = rc_ok.top;
760     ScreenToClient(hDlgWnd, &p);
761     SetWindowPos(GetDlgItem(hDlgWnd, IDOK), 0,
762     dlg_w - ok2right, p.y, 0, 0,
763     SWP_NOSIZE | SWP_NOZORDER);
764    
765     // CANCEL
766     p.x = rc_cancel.left;
767     p.y = rc_cancel.top;
768     ScreenToClient(hDlgWnd, &p);
769     SetWindowPos(GetDlgItem(hDlgWnd, IDCANCEL), 0,
770     dlg_w - ok2right, p.y, 0, 0,
771     SWP_NOSIZE | SWP_NOZORDER);
772    
773     // EDIT
774     p.x = rc_edit.left;
775     p.y = rc_edit.top;
776     ScreenToClient(hDlgWnd, &p);
777     SetWindowPos(GetDlgItem(hDlgWnd, IDC_EDIT), 0,
778 maya 3902 0, 0, dlg_w - p.x - edit2ok - ok2right, dlg_h - p.y - edit2bottom,
779 maya 3227 SWP_NOMOVE | SWP_NOZORDER);
780    
781     // �T�C�Y������
782     GetWindowRect(hDlgWnd, &rc_dlg);
783     ts.PasteDialogSize.cx = rc_dlg.right - rc_dlg.left;
784     ts.PasteDialogSize.cy = rc_dlg.bottom - rc_dlg.top;
785 yutakapon 3635
786     // status bar
787     SendMessage(hStatus , msg , wp , lp);
788 maya 3227 }
789     return TRUE;
790    
791 maya 3641 case WM_GETMINMAXINFO:
792     {
793     // �_�C�A���O�������T�C�Y����������������������������
794     LPMINMAXINFO lpmmi;
795     lpmmi = (LPMINMAXINFO)lp;
796     lpmmi->ptMinTrackSize.x = init_width;
797     lpmmi->ptMinTrackSize.y = init_height;
798     }
799     return FALSE;
800    
801 maya 3227 default:
802     return FALSE;
803     }
804     return TRUE;
805     }
806    
807 yutakapon 3535 // �t�@�C�������`���������������Atext���������������������B
808     static int search_clipboard(char *filename, char *text)
809     {
810     int ret = 0; // no hit
811     FILE *fp = NULL;
812     char buf[256];
813     int len;
814    
815     if (filename == NULL || filename[0] == '\0')
816     goto error;
817    
818     fp = fopen(filename, "r");
819     if (fp == NULL)
820     goto error;
821    
822     // TODO: ���s��256byte�������������������l��
823     while (fgets(buf, sizeof(buf), fp) != NULL) {
824     len = strlen(buf);
825     if (buf[len - 1] == '\n')
826     buf[len - 1] = '\0';
827     if (buf[0] == '\0')
828     continue;
829     if (strstr(text, buf)) { // hit
830     ret = 1;
831     break;
832     }
833     }
834    
835     error:
836     if (fp)
837     fclose(fp);
838    
839     return (ret);
840     }
841    
842    
843 maya 3227 //
844     // �N���b�v�{�[�h�����s�R�[�h�����������������A�m�F�_�C�A���O���\�������B
845     // �N���b�v�{�[�h�����X�����\�B
846     //
847     // return 0: Cancel
848     // 1: Paste OK
849     //
850     // (2008.2.3 yutaka)
851     //
852 doda 4260 int CBStartPasteConfirmChange(HWND HWin, BOOL AddCR)
853 maya 3227 {
854     UINT Cf;
855     HANDLE hText;
856     char *pText;
857     int pos;
858     int ret = 0;
859 doda 4273 BOOL confirm = FALSE;
860 maya 5071 HANDLE wide_hText;
861     LPWSTR wide_buf;
862     int mb_len;
863 maya 3227
864     if (ts.ConfirmChangePaste == 0)
865     return 1;
866    
867     if (! cv.Ready)
868     goto error;
869     if (TalkStatus!=IdTalkKeyb)
870     goto error;
871    
872 maya 5071 if (IsClipboardFormatAvailable(CF_UNICODETEXT))
873     Cf = CF_UNICODETEXT;
874     else if (IsClipboardFormatAvailable(CF_TEXT))
875 maya 3227 Cf = CF_TEXT;
876     else if (IsClipboardFormatAvailable(CF_OEMTEXT))
877     Cf = CF_OEMTEXT;
878     else
879     goto error;
880    
881     if (!OpenClipboard(HWin))
882     goto error;
883    
884 maya 5071 if (Cf == CF_UNICODETEXT) {
885     wide_hText = GetClipboardData(CF_UNICODETEXT);
886     if (wide_hText != NULL) {
887     wide_buf = GlobalLock(wide_hText);
888     mb_len = WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, NULL, 0, NULL, NULL);
889     ClipboardPtr = (char *)calloc(sizeof(char), mb_len);
890     WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, ClipboardPtr, mb_len, NULL, NULL);
891     GlobalUnlock(wide_hText);
892 doda 4273 }
893     else {
894 maya 5071 CloseClipboard();
895     goto error;
896 doda 4273 }
897 maya 5071 }
898     else {
899     hText = GetClipboardData(Cf);
900     if (hText != NULL) {
901     pText = (char *)GlobalLock(hText);
902 maya 3902 ClipboardPtr = (char *)calloc(sizeof(char), strlen(pText)+1);
903     memcpy(ClipboardPtr, pText, strlen(pText));
904     GlobalUnlock(hText);
905 maya 3227 }
906 maya 3902 else {
907     CloseClipboard();
908 maya 5071 goto error;
909 maya 3902 }
910 maya 5071 }
911     CloseClipboard();
912 maya 3227
913 maya 5071 if (AddCR) {
914     if (ts.ConfirmChangePasteCR) {
915     confirm = TRUE;
916     }
917     }
918     else {
919     pos = strcspn(ClipboardPtr, "\r\n"); // ���s����������������
920     if (ClipboardPtr[pos] != '\0' || AddCR) {
921     confirm = TRUE;
922     }
923     }
924 maya 3227
925 maya 5071 // �������T�[�`����
926     if (!confirm && search_clipboard(ts.ConfirmChangePasteStringFile, ClipboardPtr)) {
927     confirm = TRUE;
928 maya 3227 }
929    
930 maya 5071 if (confirm) {
931     PasteCanceled = 0;
932     ret = DialogBox(hInst, MAKEINTRESOURCE(IDD_CLIPBOARD_DIALOG),
933     HVTWin, (DLGPROC)OnClipboardDlgProc);
934     if (ret == 0 || ret == -1) {
935     ret = GetLastError();
936     }
937    
938     if (PasteCanceled) {
939     ret = 0;
940     goto error;
941     }
942     }
943    
944     ret = 1;
945    
946 maya 3227 error:
947 maya 5071 if (ClipboardPtr != NULL) {
948     free(ClipboardPtr);
949     ClipboardPtr = NULL;
950     }
951 maya 3227 return (ret);
952     }

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