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 4261 - (hide annotations) (download) (as text)
Tue Dec 28 04:55:01 2010 UTC (13 years, 3 months ago) by doda
File MIME type: text/x-csrc
File size: 17431 byte(s)
Alt+R の時は確認を行わないように出来るようにした。

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

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