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 3974 - (hide annotations) (download) (as text)
Mon Aug 9 12:07:13 2010 UTC (13 years, 8 months ago) by doda
File MIME type: text/x-csrc
File size: 18035 byte(s)
マクロコマンド dispstr を追加。
http://sourceforge.jp/ticket/browse.php?group_id=1412&tid=14733

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    
17     #include "clipboar.h"
18     #include "tt_res.h"
19 yutakapon 3926 #include "language.h"
20 maya 3227
21     // for clipboard copy
22     static HGLOBAL CBCopyHandle = NULL;
23     static PCHAR CBCopyPtr = NULL;
24    
25 doda 3872 #define CB_BRACKET_NONE 0
26     #define CB_BRACKET_START 1
27     #define CB_BRACKET_END 2
28 maya 3227 // for clipboard paste
29     static HGLOBAL CBMemHandle = NULL;
30     static PCHAR CBMemPtr = NULL;
31     static LONG CBMemPtr2 = 0;
32     static BOOL CBAddCR = FALSE;
33 doda 3896 static int CBBracketed = CB_BRACKET_NONE;
34 maya 3227 static BYTE CBByte;
35     static BOOL CBRetrySend;
36     static BOOL CBRetryEcho;
37     static BOOL CBSendCR;
38     static BOOL CBDDE;
39 doda 3974 static BOOL CBEchoOnly;
40 maya 3227
41     static HFONT DlgClipboardFont;
42    
43     PCHAR CBOpen(LONG MemSize)
44     {
45 maya 3393 if (MemSize==0) {
46     return (NULL);
47     }
48     if (CBCopyHandle!=NULL) {
49     return (NULL);
50     }
51     CBCopyPtr = NULL;
52     CBCopyHandle = GlobalAlloc(GMEM_MOVEABLE, MemSize);
53     if (CBCopyHandle == NULL) {
54     MessageBeep(0);
55     }
56     else {
57     CBCopyPtr = GlobalLock(CBCopyHandle);
58     if (CBCopyPtr == NULL) {
59     GlobalFree(CBCopyHandle);
60     CBCopyHandle = NULL;
61     MessageBeep(0);
62     }
63     }
64     return (CBCopyPtr);
65 maya 3227 }
66    
67     void CBClose()
68     {
69 maya 3393 BOOL Empty;
70     if (CBCopyHandle==NULL) {
71     return;
72     }
73 maya 3227
74 maya 3393 Empty = FALSE;
75     if (CBCopyPtr!=NULL) {
76     Empty = (CBCopyPtr[0]==0);
77     }
78 maya 3227
79 maya 3393 GlobalUnlock(CBCopyHandle);
80     CBCopyPtr = NULL;
81 maya 3227
82 maya 3393 if (OpenClipboard(HVTWin)) {
83     EmptyClipboard();
84     if (! Empty) {
85     SetClipboardData(CF_TEXT, CBCopyHandle);
86     }
87     CloseClipboard();
88     }
89     CBCopyHandle = NULL;
90 maya 3227 }
91    
92 doda 3872 void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed,
93 maya 3393 int BuffSize, PCHAR DataPtr, int DataSize)
94 maya 3227 //
95     // DataPtr and DataSize are used only for DDE
96     // For clipboard, BuffSize should be 0
97     // DataSize should be <= BuffSize
98     {
99 maya 3393 UINT Cf;
100 maya 3227
101 maya 3393 if (! cv.Ready) {
102     return;
103     }
104     if (TalkStatus!=IdTalkKeyb) {
105     return;
106     }
107 maya 3227
108 maya 3393 CBAddCR = AddCR;
109 doda 3872 if (Bracketed) {
110     CBBracketed = CB_BRACKET_START;
111     }
112 maya 3227
113 maya 3393 if (BuffSize==0) { // for clipboar
114 yutakapon 3926 if (in_utf(ts) &&
115     IsClipboardFormatAvailable(CF_UNICODETEXT)) {
116     // UTF-8�������AUnicode(wchar_t)���������������B
117     Cf = CF_UNICODETEXT;
118     } else if (IsClipboardFormatAvailable(CF_TEXT)) {
119 maya 3393 Cf = CF_TEXT;
120     }
121     else if (IsClipboardFormatAvailable(CF_OEMTEXT)) {
122     Cf = CF_OEMTEXT;
123     }
124     else {
125     return;
126     }
127     }
128 maya 3227
129 doda 3974 CBEchoOnly = FALSE;
130    
131 maya 3393 CBMemHandle = NULL;
132     CBMemPtr = NULL;
133     CBMemPtr2 = 0;
134     CBDDE = FALSE;
135     if (BuffSize==0) { //clipboard
136     if (OpenClipboard(HWin)) {
137     CBMemHandle = GetClipboardData(Cf);
138     }
139     if (CBMemHandle!=NULL) {
140     TalkStatus=IdTalkCB;
141     }
142     }
143     else { // dde
144     CBMemHandle = GlobalAlloc(GHND,BuffSize);
145     if (CBMemHandle != NULL) {
146     CBDDE = TRUE;
147     CBMemPtr = GlobalLock(CBMemHandle);
148     if (CBMemPtr != NULL) {
149     memcpy(CBMemPtr,DataPtr,DataSize);
150     GlobalUnlock(CBMemHandle);
151     CBMemPtr=NULL;
152     TalkStatus=IdTalkCB;
153     }
154     }
155     }
156     CBRetrySend = FALSE;
157     CBRetryEcho = FALSE;
158     CBSendCR = FALSE;
159     if (TalkStatus != IdTalkCB) {
160     CBEndPaste();
161     }
162 maya 3227 }
163    
164 doda 3974 void CBStartEcho(PCHAR DataPtr, int DataSize)
165     {
166     if (! cv.Ready) {
167     return;
168     }
169     if (TalkStatus!=IdTalkKeyb) {
170     return;
171     }
172    
173     CBEchoOnly = TRUE;
174     CBMemPtr2 = 0;
175     CBRetryEcho = FALSE;
176     CBSendCR = FALSE;
177    
178     CBDDE = FALSE;
179     if ((CBMemHandle = GlobalAlloc(GHND, DataSize)) != NULL) {
180     CBDDE = TRUE;
181     if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
182     memcpy(CBMemPtr, DataPtr, DataSize);
183     GlobalUnlock(CBMemHandle);
184     CBMemPtr=NULL;
185     TalkStatus=IdTalkCB;
186     }
187     }
188    
189     if (TalkStatus != IdTalkCB) {
190     CBEndPaste();
191     }
192     }
193    
194 maya 3227 // �����������N���b�v�{�[�h������DDE�f�[�^���[�������������B
195     //
196     // CBMemHandle�n���h�����O���[�o�������������A�����������I�������������A
197     // �����N���b�v�{�[�h������DDE�f�[�^�������������������������i�j�����������\�������j�B
198     // �����A�f�[�^���� null-terminate �����������������O�����������������A�������f�[�^����
199     // �����������B
200     // (2006.11.6 yutaka)
201     void CBSend()
202     {
203 maya 3393 int c;
204     BOOL EndFlag;
205 doda 3688 static DWORD lastcr;
206 doda 3872 static char BracketStart[] = "\033[200~";
207     static char BracketEnd[] = "\033[201~";
208     static int BracketPtr = 0;
209 doda 3688 DWORD now;
210 yutakapon 3926 char *ptr;
211     wchar_t *wptr;
212     char *mptr;
213     int mlen;
214 maya 3227
215 maya 3393 if (CBMemHandle==NULL) {
216     return;
217     }
218 maya 3227
219 doda 3974 if (CBEchoOnly) {
220     CBEcho();
221     return;
222     }
223    
224 doda 3688 now = GetTickCount();
225 doda 3691 if (now - lastcr < (DWORD)ts.PasteDelayPerLine) {
226 doda 3688 return;
227     }
228    
229 maya 3393 if (CBRetrySend) {
230     CBRetryEcho = (ts.LocalEcho>0);
231     c = CommTextOut(&cv,(PCHAR)&CBByte,1);
232     CBRetrySend = (c==0);
233     if (CBRetrySend) {
234     return;
235     }
236     }
237 maya 3227
238 maya 3393 if (CBRetryEcho) {
239     c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
240     CBRetryEcho = (c==0);
241     if (CBRetryEcho) {
242     return;
243     }
244     }
245 maya 3227
246 yutakapon 3926 ptr = GlobalLock(CBMemHandle);
247     if (ptr==NULL) {
248 maya 3393 return;
249     }
250 maya 3227
251 yutakapon 3926 mptr = NULL;
252     if (in_utf(ts)) {
253     /* Unicode����UTF-8�����������B������ null �����������K�v�����������A
254     * +1 �������������������B
255     */
256     wptr = (wchar_t *)ptr;
257     convert_wchar_to_utf8(wptr, wcslen(wptr) + 1, NULL, &mlen);
258     mptr = malloc(sizeof(char) * mlen);
259     convert_wchar_to_utf8(wptr, wcslen(wptr) + 1, mptr, &mlen);
260     CBMemPtr = mptr;
261    
262     } else {
263     CBMemPtr = ptr;
264     }
265    
266 maya 3393 do {
267     if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a)) {
268     CBMemPtr2++;
269     // added PasteDelayPerLine (2009.4.12 maya)
270 doda 3690 if (ts.PasteDelayPerLine > 0) {
271     lastcr = now;
272     CBSendCR = FALSE;
273     SetTimer(HVTWin, IdPasteDelayTimer, ts.PasteDelayPerLine, NULL);
274     break;
275     }
276 maya 3393 }
277    
278     EndFlag = (CBMemPtr[CBMemPtr2]==0);
279 doda 3872 if (CBBracketed == CB_BRACKET_START) {
280     CBByte = BracketStart[BracketPtr++];
281     if (BracketPtr >= sizeof(BracketStart) - 1) {
282     CBBracketed = CB_BRACKET_END;
283     BracketPtr = 0;
284     }
285     }
286     else if (! EndFlag) {
287 maya 3393 CBByte = CBMemPtr[CBMemPtr2];
288     CBMemPtr2++;
289 maya 3227 // Decoding characters which are encoded by MACRO
290     // to support NUL character sending
291     //
292     // [encoded character] --> [decoded character]
293     // 01 01 --> 00
294     // 01 02 --> 01
295 maya 3393 if (CBByte==0x01) { /* 0x01 from MACRO */
296     CBByte = CBMemPtr[CBMemPtr2];
297     CBMemPtr2++;
298     CBByte = CBByte - 1; // character just after 0x01
299     }
300     }
301     else if (CBAddCR) {
302     EndFlag = FALSE;
303     CBAddCR = FALSE;
304     CBByte = 0x0d;
305     }
306 doda 3872 else if (CBBracketed == CB_BRACKET_END) {
307     EndFlag = FALSE;
308     CBByte = BracketEnd[BracketPtr++];
309     if (BracketPtr >= sizeof(BracketEnd) - 1) {
310     CBBracketed = CB_BRACKET_NONE;
311     BracketPtr = 0;
312     }
313     }
314 maya 3393 else {
315     CBEndPaste();
316 yutakapon 3926 if (mptr)
317     free(mptr);
318 maya 3393 return;
319     }
320 maya 3227
321 maya 3393 if (! EndFlag) {
322     c = CommTextOut(&cv,(PCHAR)&CBByte,1);
323     CBSendCR = (CBByte==0x0D);
324     CBRetrySend = (c==0);
325     if ((! CBRetrySend) &&
326     (ts.LocalEcho>0)) {
327     c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
328     CBRetryEcho = (c==0);
329     }
330     }
331     else {
332     c=0;
333     }
334     }
335     while (c>0);
336 maya 3227
337 yutakapon 3926 if (mptr)
338     free(mptr);
339    
340     if (ptr !=NULL) {
341 maya 3393 GlobalUnlock(CBMemHandle);
342     CBMemPtr=NULL;
343     }
344 maya 3227 }
345    
346 doda 3974 void CBEcho()
347     {
348     if (CBMemHandle==NULL) {
349     return;
350     }
351    
352     if (CBRetryEcho && CommTextEcho(&cv,(PCHAR)&CBByte,1) == 0) {
353     return;
354     }
355    
356     if ((CBMemPtr = GlobalLock(CBMemHandle)) == NULL) {
357     return;
358     }
359    
360     do {
361     if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a)) {
362     CBMemPtr2++;
363     }
364    
365     if (CBMemPtr[CBMemPtr2] == 0) {
366     CBRetryEcho = FALSE;
367     CBEndPaste();
368     return;
369     }
370    
371     CBByte = CBMemPtr[CBMemPtr2];
372     CBMemPtr2++;
373    
374     // Decoding characters which are encoded by MACRO
375     // to support NUL character sending
376     //
377     // [encoded character] --> [decoded character]
378     // 01 01 --> 00
379     // 01 02 --> 01
380     if (CBByte==0x01) { /* 0x01 from MACRO */
381     CBByte = CBMemPtr[CBMemPtr2];
382     CBMemPtr2++;
383     CBByte = CBByte - 1; // character just after 0x01
384     }
385    
386     CBSendCR = (CBByte==0x0D);
387    
388     } while (CommTextEcho(&cv,(PCHAR)&CBByte,1) > 0);
389    
390     CBRetryEcho = TRUE;
391    
392     if (CBMemHandle != NULL) {
393     GlobalUnlock(CBMemHandle);
394     CBMemPtr=NULL;
395     }
396     }
397    
398 maya 3227 void CBEndPaste()
399     {
400 maya 3393 TalkStatus = IdTalkKeyb;
401 maya 3227
402 maya 3393 if (CBMemHandle!=NULL) {
403     if (CBMemPtr!=NULL) {
404     GlobalUnlock(CBMemHandle);
405     }
406     if (CBDDE) {
407     GlobalFree(CBMemHandle);
408     }
409     }
410     if (!CBDDE) {
411     CloseClipboard();
412     }
413 maya 3227
414 maya 3393 CBDDE = FALSE;
415     CBMemHandle = NULL;
416     CBMemPtr = NULL;
417     CBMemPtr2 = 0;
418     CBAddCR = FALSE;
419 doda 3974 CBEchoOnly = FALSE;
420 maya 3227 }
421    
422    
423     static char *ClipboardPtr = NULL;
424     static int PasteCanceled = 0;
425    
426     static LRESULT CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
427     {
428     LOGFONT logfont;
429     HFONT font;
430     char uimsg[MAX_UIMSG];
431     //char *p;
432     POINT p;
433     RECT rc_dsk, rc_dlg;
434     int dlg_height, dlg_width;
435     OSVERSIONINFO osvi;
436 maya 3902 static int ok2right, edit2ok, edit2bottom;
437     RECT rc_edit, rc_ok, rc_cancel;
438 yutakapon 3635 // for status bar
439     static HWND hStatus = NULL;
440 maya 3641 static init_width, init_height;
441 maya 3227
442     switch (msg) {
443     case WM_INITDIALOG:
444     #if 0
445     for (p = ClipboardPtr; *p ; p++) {
446     char buf[20];
447     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%02x ", *p);
448     OutputDebugString(buf);
449     }
450     #endif
451    
452     font = (HFONT)SendMessage(hDlgWnd, WM_GETFONT, 0, 0);
453     GetObject(font, sizeof(LOGFONT), &logfont);
454     if (get_lang_font("DLG_TAHOMA_FONT", hDlgWnd, &logfont, &DlgClipboardFont, ts.UILanguageFile)) {
455     SendDlgItemMessage(hDlgWnd, IDC_EDIT, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
456     SendDlgItemMessage(hDlgWnd, IDOK, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
457     SendDlgItemMessage(hDlgWnd, IDCANCEL, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
458     }
459     else {
460     DlgClipboardFont = NULL;
461     }
462    
463     GetWindowText(hDlgWnd, uimsg, sizeof(uimsg));
464     get_lang_msg("DLG_CLIPBOARD_TITLE", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
465     SetWindowText(hDlgWnd, ts.UIMsg);
466     GetDlgItemText(hDlgWnd, IDCANCEL, uimsg, sizeof(uimsg));
467     get_lang_msg("BTN_CANCEL", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
468     SetDlgItemText(hDlgWnd, IDCANCEL, ts.UIMsg);
469     GetDlgItemText(hDlgWnd, IDOK, uimsg, sizeof(uimsg));
470     get_lang_msg("BTN_OK", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
471     SetDlgItemText(hDlgWnd, IDOK, ts.UIMsg);
472    
473     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_SETTEXT, 0, (LPARAM)ClipboardPtr);
474    
475     DispConvScreenToWin(CursorX, CursorY, &p.x, &p.y);
476     ClientToScreen(HVTWin, &p);
477    
478     // �L�����b�g���������������o���������������\���t����������
479     // �m�F�E�C���h�E�����������������\���������������������B
480     // �E�C���h�E���������o������������������ (2008.4.24 maya)
481     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
482     GetVersionEx(&osvi);
483 maya 3509 if ( (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 4) ||
484     (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && osvi.dwMinorVersion < 10) ) {
485     // NT4.0, 95 ���}���`���j�^API��������
486 maya 3227 SystemParametersInfo(SPI_GETWORKAREA, 0, &rc_dsk, 0);
487     }
488     else {
489     HMONITOR hm;
490     POINT pt;
491     MONITORINFO mi;
492    
493     pt.x = p.x;
494     pt.y = p.y;
495     hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
496    
497     mi.cbSize = sizeof(MONITORINFO);
498     GetMonitorInfo(hm, &mi);
499     rc_dsk = mi.rcWork;
500     }
501     GetWindowRect(hDlgWnd, &rc_dlg);
502     dlg_height = rc_dlg.bottom-rc_dlg.top;
503     dlg_width = rc_dlg.right-rc_dlg.left;
504     if (p.y < rc_dsk.top) {
505     p.y = rc_dsk.top;
506     }
507     else if (p.y + dlg_height > rc_dsk.bottom) {
508     p.y = rc_dsk.bottom - dlg_height;
509     }
510     if (p.x < rc_dsk.left) {
511     p.x = rc_dsk.left;
512     }
513     else if (p.x + dlg_width > rc_dsk.right) {
514     p.x = rc_dsk.right - dlg_width;
515     }
516    
517     SetWindowPos(hDlgWnd, NULL, p.x, p.y,
518     0, 0, SWP_NOSIZE | SWP_NOZORDER);
519    
520 maya 3641 // �_�C�A���O�������T�C�Y������
521     GetWindowRect(hDlgWnd, &rc_dlg);
522     init_width = rc_dlg.right - rc_dlg.left;
523     init_height = rc_dlg.bottom - rc_dlg.top;
524    
525 maya 3227 // �����T�C�Y�����K�v���l���v�Z
526     GetClientRect(hDlgWnd, &rc_dlg);
527     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
528     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
529    
530     p.x = rc_dlg.right;
531     p.y = rc_dlg.bottom;
532     ClientToScreen(hDlgWnd, &p);
533     ok2right = p.x - rc_ok.left;
534 maya 3902 edit2bottom = p.y - rc_edit.bottom;
535 maya 3227 edit2ok = rc_ok.left - rc_edit.right;
536    
537     // �T�C�Y������
538     SetWindowPos(hDlgWnd, NULL, 0, 0,
539     ts.PasteDialogSize.cx, ts.PasteDialogSize.cy,
540     SWP_NOZORDER | SWP_NOMOVE);
541    
542 yutakapon 3635 // ���T�C�Y�A�C�R�����E�����\���������������A�X�e�[�^�X�o�[���t�����B
543     InitCommonControls();
544     hStatus = CreateStatusWindow(
545     WS_CHILD | WS_VISIBLE |
546     CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hDlgWnd, 1);
547    
548 maya 3227 return TRUE;
549    
550     case WM_COMMAND:
551     switch (LOWORD(wp)) {
552     case IDOK:
553     {
554     int len = SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXTLENGTH, 0, 0);
555     HGLOBAL hMem;
556     char *buf;
557    
558 maya 3902 if (OpenClipboard(hDlgWnd) != 0) {
559     hMem = GlobalAlloc(GMEM_MOVEABLE, len + 1);
560     buf = GlobalLock(hMem);
561     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXT, len + 1, (LPARAM)buf);
562     GlobalUnlock(hMem);
563 maya 3227
564 maya 3902 EmptyClipboard();
565     SetClipboardData(CF_TEXT, hMem);
566     CloseClipboard();
567     // hMem���N���b�v�{�[�h�������������������A�j�����������������B
568     }
569 maya 3227
570     if (DlgClipboardFont != NULL) {
571     DeleteObject(DlgClipboardFont);
572     }
573    
574 yutakapon 3635 DestroyWindow(hStatus);
575 maya 3227 EndDialog(hDlgWnd, IDOK);
576     }
577     break;
578    
579     case IDCANCEL:
580     PasteCanceled = 1;
581    
582     if (DlgClipboardFont != NULL) {
583     DeleteObject(DlgClipboardFont);
584     }
585    
586 yutakapon 3635 DestroyWindow(hStatus);
587 maya 3227 EndDialog(hDlgWnd, IDCANCEL);
588     break;
589    
590     default:
591     return FALSE;
592     }
593    
594     #if 0
595     case WM_CLOSE:
596     PasteCanceled = 1;
597     EndDialog(hDlgWnd, 0);
598     return TRUE;
599     #endif
600    
601     case WM_SIZE:
602     {
603     // ���z�u
604     POINT p;
605     int dlg_w, dlg_h;
606    
607     GetClientRect(hDlgWnd, &rc_dlg);
608     dlg_w = rc_dlg.right;
609     dlg_h = rc_dlg.bottom;
610    
611     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
612     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
613     GetWindowRect(GetDlgItem(hDlgWnd, IDCANCEL), &rc_cancel);
614    
615     // OK
616     p.x = rc_ok.left;
617     p.y = rc_ok.top;
618     ScreenToClient(hDlgWnd, &p);
619     SetWindowPos(GetDlgItem(hDlgWnd, IDOK), 0,
620     dlg_w - ok2right, p.y, 0, 0,
621     SWP_NOSIZE | SWP_NOZORDER);
622    
623     // CANCEL
624     p.x = rc_cancel.left;
625     p.y = rc_cancel.top;
626     ScreenToClient(hDlgWnd, &p);
627     SetWindowPos(GetDlgItem(hDlgWnd, IDCANCEL), 0,
628     dlg_w - ok2right, p.y, 0, 0,
629     SWP_NOSIZE | SWP_NOZORDER);
630    
631     // EDIT
632     p.x = rc_edit.left;
633     p.y = rc_edit.top;
634     ScreenToClient(hDlgWnd, &p);
635     SetWindowPos(GetDlgItem(hDlgWnd, IDC_EDIT), 0,
636 maya 3902 0, 0, dlg_w - p.x - edit2ok - ok2right, dlg_h - p.y - edit2bottom,
637 maya 3227 SWP_NOMOVE | SWP_NOZORDER);
638    
639     // �T�C�Y������
640     GetWindowRect(hDlgWnd, &rc_dlg);
641     ts.PasteDialogSize.cx = rc_dlg.right - rc_dlg.left;
642     ts.PasteDialogSize.cy = rc_dlg.bottom - rc_dlg.top;
643 yutakapon 3635
644     // status bar
645     SendMessage(hStatus , msg , wp , lp);
646 maya 3227 }
647     return TRUE;
648    
649 maya 3641 case WM_GETMINMAXINFO:
650     {
651     // �_�C�A���O�������T�C�Y����������������������������
652     LPMINMAXINFO lpmmi;
653     lpmmi = (LPMINMAXINFO)lp;
654     lpmmi->ptMinTrackSize.x = init_width;
655     lpmmi->ptMinTrackSize.y = init_height;
656     }
657     return FALSE;
658    
659 maya 3227 default:
660     return FALSE;
661     }
662     return TRUE;
663     }
664    
665 yutakapon 3535 // �t�@�C�������`���������������Atext���������������������B
666     static int search_clipboard(char *filename, char *text)
667     {
668     int ret = 0; // no hit
669     FILE *fp = NULL;
670     char buf[256];
671     int len;
672    
673     if (filename == NULL || filename[0] == '\0')
674     goto error;
675    
676     fp = fopen(filename, "r");
677     if (fp == NULL)
678     goto error;
679    
680     // TODO: ���s��256byte�������������������l��
681     while (fgets(buf, sizeof(buf), fp) != NULL) {
682     len = strlen(buf);
683     if (buf[len - 1] == '\n')
684     buf[len - 1] = '\0';
685     if (buf[0] == '\0')
686     continue;
687     if (strstr(text, buf)) { // hit
688     ret = 1;
689     break;
690     }
691     }
692    
693     error:
694     if (fp)
695     fclose(fp);
696    
697     return (ret);
698     }
699    
700    
701 maya 3227 //
702     // �N���b�v�{�[�h�����s�R�[�h�����������������A�m�F�_�C�A���O���\�������B
703     // �N���b�v�{�[�h�����X�����\�B
704     //
705     // return 0: Cancel
706     // 1: Paste OK
707     //
708     // (2008.2.3 yutaka)
709     //
710     int CBStartPasteConfirmChange(HWND HWin)
711     {
712     UINT Cf;
713     HANDLE hText;
714     char *pText;
715     int pos;
716     int ret = 0;
717 yutakapon 3535 int confirm = 0;
718 maya 3227
719     if (ts.ConfirmChangePaste == 0)
720     return 1;
721    
722     if (! cv.Ready)
723     goto error;
724     if (TalkStatus!=IdTalkKeyb)
725     goto error;
726    
727     if (IsClipboardFormatAvailable(CF_TEXT))
728     Cf = CF_TEXT;
729     else if (IsClipboardFormatAvailable(CF_OEMTEXT))
730     Cf = CF_OEMTEXT;
731     else
732     goto error;
733    
734     if (!OpenClipboard(HWin))
735     goto error;
736    
737     hText = GetClipboardData(Cf);
738    
739     if (hText != NULL) {
740     pText = (char *)GlobalLock(hText);
741     pos = strcspn(pText, "\r\n"); // ���s����������������
742     if (pText[pos] != '\0') {
743 yutakapon 3535 confirm = 1;
744    
745     } else {
746     // �������T�[�`����
747     if (search_clipboard(ts.ConfirmChangePasteStringFile, pText)) {
748     confirm = 1;
749     }
750    
751     }
752    
753     if (confirm) {
754 maya 3902 ClipboardPtr = (char *)calloc(sizeof(char), strlen(pText)+1);
755     memcpy(ClipboardPtr, pText, strlen(pText));
756     GlobalUnlock(hText);
757     CloseClipboard();
758 maya 3227 PasteCanceled = 0;
759     ret = DialogBox(hInst, MAKEINTRESOURCE(IDD_CLIPBOARD_DIALOG),
760 maya 3902 HVTWin, (DLGPROC)OnClipboardDlgProc);
761     free(ClipboardPtr);
762 maya 3227 if (ret == 0 || ret == -1) {
763     ret = GetLastError();
764     }
765    
766     if (PasteCanceled) {
767     ret = 0;
768     goto error;
769     }
770    
771     }
772 maya 3902 else {
773     GlobalUnlock(hText);
774     CloseClipboard();
775     }
776 maya 3227
777     ret = 1;
778    
779     }
780    
781     error:
782     return (ret);
783     }

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