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 2560 - (hide annotations) (download) (as text)
Sun Jul 13 08:21:45 2008 UTC (15 years, 9 months ago) by yutakapon
Original Path: teraterm/trunk/teraterm/clipboar.c
File MIME type: text/x-csrc
File size: 11138 byte(s)
クリップボード用ダイアログをリサイズ可能としようとしたが、失敗。
http://sourceforge.jp/tracker/index.php?func=detail&aid=13021&group_id=1412&atid=5336
http://d.hatena.ne.jp/u-ichi/20080710/1215621656

1 maya 2476 /* 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 maya 2488 #include "vtdisp.h"
9 maya 2476 #include <string.h>
10     #include <stdlib.h>
11     #include <stdio.h>
12    
13     #include "ttwinman.h"
14     #include "ttcommon.h"
15    
16     #include "clipboar.h"
17     #include "tt_res.h"
18    
19     // for clipboard copy
20     static HGLOBAL CBCopyHandle = NULL;
21     static PCHAR CBCopyPtr = NULL;
22    
23     // for clipboard paste
24     static HGLOBAL CBMemHandle = NULL;
25     static PCHAR CBMemPtr = NULL;
26     static LONG CBMemPtr2 = 0;
27     static BOOL CBAddCR = FALSE;
28     static BYTE CBByte;
29     static BOOL CBRetrySend;
30     static BOOL CBRetryEcho;
31     static BOOL CBSendCR;
32     static BOOL CBDDE;
33    
34     static HFONT DlgClipboardFont;
35    
36     PCHAR CBOpen(LONG MemSize)
37     {
38     if (MemSize==0) return (NULL);
39     if (CBCopyHandle!=NULL) return (NULL);
40     CBCopyPtr = NULL;
41     CBCopyHandle = GlobalAlloc(GMEM_MOVEABLE, MemSize);
42     if (CBCopyHandle == NULL)
43     MessageBeep(0);
44     else {
45     CBCopyPtr = GlobalLock(CBCopyHandle);
46     if (CBCopyPtr == NULL)
47     {
48     GlobalFree(CBCopyHandle);
49     CBCopyHandle = NULL;
50     MessageBeep(0);
51     }
52     }
53     return (CBCopyPtr);
54     }
55    
56     void CBClose()
57     {
58     BOOL Empty;
59     if (CBCopyHandle==NULL) return;
60    
61     Empty = FALSE;
62     if (CBCopyPtr!=NULL)
63     Empty = (CBCopyPtr[0]==0);
64    
65     GlobalUnlock(CBCopyHandle);
66     CBCopyPtr = NULL;
67    
68     if (OpenClipboard(HVTWin))
69     {
70     EmptyClipboard();
71     if (! Empty)
72     SetClipboardData(CF_TEXT, CBCopyHandle);
73     CloseClipboard();
74     }
75     CBCopyHandle = NULL;
76     }
77    
78     void CBStartPaste(HWND HWin, BOOL AddCR,
79     int BuffSize, PCHAR DataPtr, int DataSize)
80     //
81     // DataPtr and DataSize are used only for DDE
82     // For clipboard, BuffSize should be 0
83     // DataSize should be <= BuffSize
84     {
85     UINT Cf;
86    
87     if (! cv.Ready) return;
88     if (TalkStatus!=IdTalkKeyb) return;
89    
90     CBAddCR = AddCR;
91    
92     if (BuffSize==0) // for clipboard
93     {
94     if (IsClipboardFormatAvailable(CF_TEXT))
95     Cf = CF_TEXT;
96     else if (IsClipboardFormatAvailable(CF_OEMTEXT))
97     Cf = CF_OEMTEXT;
98     else return;
99     }
100    
101     CBMemHandle = NULL;
102     CBMemPtr = NULL;
103     CBMemPtr2 = 0;
104     CBDDE = FALSE;
105     if (BuffSize==0) //clipboard
106     {
107     if (OpenClipboard(HWin))
108     CBMemHandle = GetClipboardData(Cf);
109     if (CBMemHandle!=NULL) TalkStatus=IdTalkCB;
110     }
111     else { // dde
112     CBMemHandle = GlobalAlloc(GHND,BuffSize);
113     if (CBMemHandle != NULL)
114     {
115     CBDDE = TRUE;
116     CBMemPtr = GlobalLock(CBMemHandle);
117     if (CBMemPtr != NULL)
118     {
119     memcpy(CBMemPtr,DataPtr,DataSize);
120     GlobalUnlock(CBMemHandle);
121     CBMemPtr=NULL;
122     TalkStatus=IdTalkCB;
123     }
124     }
125     }
126     CBRetrySend = FALSE;
127     CBRetryEcho = FALSE;
128     CBSendCR = FALSE;
129     if (TalkStatus != IdTalkCB) CBEndPaste();
130     }
131    
132     // �����������N���b�v�{�[�h������DDE�f�[�^���[�������������B
133     //
134     // CBMemHandle�n���h�����O���[�o�������������A�����������I�������������A
135     // �����N���b�v�{�[�h������DDE�f�[�^�������������������������i�j�����������\�������j�B
136     // �����A�f�[�^���� null-terminate �����������������O�����������������A�������f�[�^����
137     // �����������B
138     // (2006.11.6 yutaka)
139     void CBSend()
140     {
141     int c;
142     BOOL EndFlag;
143    
144     if (CBMemHandle==NULL) return;
145    
146     if (CBRetrySend)
147     {
148     CBRetryEcho = (ts.LocalEcho>0);
149     c = CommTextOut(&cv,(PCHAR)&CBByte,1);
150     CBRetrySend = (c==0);
151     if (CBRetrySend) return;
152     }
153    
154     if (CBRetryEcho)
155     {
156     c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
157     CBRetryEcho = (c==0);
158     if (CBRetryEcho) return;
159     }
160    
161     CBMemPtr = GlobalLock(CBMemHandle);
162     if (CBMemPtr==NULL) return;
163    
164     do {
165     if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a))
166     CBMemPtr2++;
167    
168     EndFlag = (CBMemPtr[CBMemPtr2]==0);
169     if (! EndFlag)
170     {
171     CBByte = CBMemPtr[CBMemPtr2];
172     CBMemPtr2++;
173     // Decoding characters which are encoded by MACRO
174     // to support NUL character sending
175     //
176     // [encoded character] --> [decoded character]
177     // 01 01 --> 00
178     // 01 02 --> 01
179     if (CBByte==0x01) /* 0x01 from MACRO */
180     {
181     CBByte = CBMemPtr[CBMemPtr2];
182     CBMemPtr2++;
183     CBByte = CBByte - 1; // character just after 0x01
184     }
185     }
186     else if (CBAddCR)
187     {
188     EndFlag = FALSE;
189     CBAddCR = FALSE;
190     CBByte = 0x0d;
191     }
192     else {
193     CBEndPaste();
194     return;
195     }
196    
197     if (! EndFlag)
198     {
199     c = CommTextOut(&cv,(PCHAR)&CBByte,1);
200     CBSendCR = (CBByte==0x0D);
201     CBRetrySend = (c==0);
202     if ((! CBRetrySend) &&
203     (ts.LocalEcho>0))
204     {
205     c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
206     CBRetryEcho = (c==0);
207     }
208     }
209     else
210     c=0;
211     }
212     while (c>0);
213    
214     if (CBMemPtr!=NULL)
215     {
216     GlobalUnlock(CBMemHandle);
217     CBMemPtr=NULL;
218     }
219     }
220    
221     void CBEndPaste()
222     {
223     TalkStatus = IdTalkKeyb;
224    
225     if (CBMemHandle!=NULL)
226     {
227     if (CBMemPtr!=NULL)
228     GlobalUnlock(CBMemHandle);
229     if (CBDDE)
230     GlobalFree(CBMemHandle);
231     }
232     if (!CBDDE) CloseClipboard();
233    
234     CBDDE = FALSE;
235     CBMemHandle = NULL;
236     CBMemPtr = NULL;
237     CBMemPtr2 = 0;
238     CBAddCR = FALSE;
239     }
240    
241    
242     static char *ClipboardPtr = NULL;
243     static int PasteCanceled = 0;
244    
245     static LRESULT CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
246     {
247 yutakapon 2560 static int cur_dlg_height, cur_dlg_width;
248 maya 2476 LOGFONT logfont;
249     HFONT font;
250     char uimsg[MAX_UIMSG];
251 maya 2489 //char *p;
252     POINT p;
253     RECT rc_dsk, rc_dlg;
254     int dlg_height, dlg_width;
255     OSVERSIONINFO osvi;
256 maya 2476
257     switch (msg) {
258     case WM_INITDIALOG:
259     #if 0
260     for (p = ClipboardPtr; *p ; p++) {
261     char buf[20];
262     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%02x ", *p);
263     OutputDebugString(buf);
264     }
265     #endif
266    
267     font = (HFONT)SendMessage(hDlgWnd, WM_GETFONT, 0, 0);
268     GetObject(font, sizeof(LOGFONT), &logfont);
269     if (get_lang_font("DLG_TAHOMA_FONT", hDlgWnd, &logfont, &DlgClipboardFont, ts.UILanguageFile)) {
270     SendDlgItemMessage(hDlgWnd, IDC_EDIT, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
271     SendDlgItemMessage(hDlgWnd, IDC_CLIPBOARD_INFO, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
272     SendDlgItemMessage(hDlgWnd, IDOK, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
273     SendDlgItemMessage(hDlgWnd, IDCANCEL, WM_SETFONT, (WPARAM)DlgClipboardFont, MAKELPARAM(TRUE,0));
274     }
275     else {
276     DlgClipboardFont = NULL;
277     }
278    
279     GetWindowText(hDlgWnd, uimsg, sizeof(uimsg));
280     get_lang_msg("DLG_CLIPBOARD_TITLE", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
281     SetWindowText(hDlgWnd, ts.UIMsg);
282     GetDlgItemText(hDlgWnd, IDC_CLIPBOARD_INFO, uimsg, sizeof(uimsg));
283     get_lang_msg("DLG_CLIPBOARD_INFO", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
284     SetDlgItemText(hDlgWnd, IDC_CLIPBOARD_INFO, ts.UIMsg);
285     GetDlgItemText(hDlgWnd, IDCANCEL, uimsg, sizeof(uimsg));
286     get_lang_msg("BTN_CANCEL", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
287     SetDlgItemText(hDlgWnd, IDCANCEL, ts.UIMsg);
288     GetDlgItemText(hDlgWnd, IDOK, uimsg, sizeof(uimsg));
289     get_lang_msg("BTN_OK", ts.UIMsg, sizeof(ts.UIMsg), uimsg, ts.UILanguageFile);
290     SetDlgItemText(hDlgWnd, IDOK, ts.UIMsg);
291    
292     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_SETTEXT, 0, (LPARAM)ClipboardPtr);
293 maya 2480
294 maya 2488 DispConvScreenToWin(CursorX, CursorY, &p.x, &p.y);
295     ClientToScreen(HVTWin, &p);
296 maya 2489
297     // �L�����b�g���������������o���������������\���t����������
298     // �m�F�E�C���h�E�����������������\���������������������B
299     // �E�C���h�E���������o������������������ (2008.4.24 mya)
300     osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
301     GetVersionEx(&osvi);
302     if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && osvi.dwMajorVersion == 4) {
303     // NT4.0 ���}���`���j�^API��������
304     SystemParametersInfo(SPI_GETWORKAREA, 0, &rc_dsk, 0);
305     }
306     else {
307     HMONITOR hm;
308     POINT pt;
309     MONITORINFO mi;
310    
311     pt.x = p.x;
312     pt.y = p.y;
313     hm = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
314    
315     mi.cbSize = sizeof(MONITORINFO);
316     GetMonitorInfo(hm, &mi);
317     rc_dsk = mi.rcWork;
318     }
319     GetWindowRect(hDlgWnd, &rc_dlg);
320     dlg_height = rc_dlg.bottom-rc_dlg.top;
321     dlg_width = rc_dlg.right-rc_dlg.left;
322     if (p.y < rc_dsk.top) {
323     p.y = rc_dsk.top;
324     }
325     else if (p.y + dlg_height > rc_dsk.bottom) {
326     p.y = rc_dsk.bottom - dlg_height;
327     }
328     if (p.x < rc_dsk.left) {
329     p.x = rc_dsk.left;
330     }
331     else if (p.x + dlg_width > rc_dsk.right) {
332     p.x = rc_dsk.right - dlg_width;
333     }
334    
335 maya 2488 SetWindowPos(hDlgWnd, NULL, p.x, p.y,
336     0, 0, SWP_NOSIZE | SWP_NOZORDER);
337 maya 2480
338 yutakapon 2560 // �����T�C�Y������
339     cur_dlg_height = dlg_height;
340     cur_dlg_width = dlg_width;
341    
342 maya 2476 return TRUE;
343    
344     case WM_COMMAND:
345     switch (LOWORD(wp)) {
346     case IDOK:
347     {
348     int len = SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXTLENGTH, 0, 0);
349     HGLOBAL hMem;
350     char *buf;
351    
352     hMem = GlobalAlloc(GMEM_MOVEABLE, len + 1);
353     buf = GlobalLock(hMem);
354     SendMessage(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXT, len + 1, (LPARAM)buf);
355     GlobalUnlock(hMem);
356    
357     EmptyClipboard();
358     SetClipboardData(CF_TEXT, hMem);
359    
360     // hMem���N���b�v�{�[�h�������������������A�j�����������������B
361    
362     if (DlgClipboardFont != NULL) {
363     DeleteObject(DlgClipboardFont);
364     }
365    
366     EndDialog(hDlgWnd, IDOK);
367     }
368     break;
369    
370     case IDCANCEL:
371     PasteCanceled = 1;
372    
373     if (DlgClipboardFont != NULL) {
374     DeleteObject(DlgClipboardFont);
375     }
376    
377     EndDialog(hDlgWnd, IDCANCEL);
378     break;
379    
380     default:
381     return FALSE;
382     }
383    
384     #if 0
385     case WM_CLOSE:
386     PasteCanceled = 1;
387     EndDialog(hDlgWnd, 0);
388     return TRUE;
389     #endif
390    
391 yutakapon 2560 case WM_SIZE:
392     {
393     #if 0
394     double dw, dh;
395     RECT rc_edit;
396     double nw, nh;
397    
398     GetWindowRect(hDlgWnd, &rc_dlg);
399     dlg_height = rc_dlg.bottom-rc_dlg.top;
400     dlg_width = rc_dlg.right-rc_dlg.left;
401    
402     // �{���v�Z
403     dw = (double)dlg_width / cur_dlg_width;
404     dh = (double)dlg_height / cur_dlg_height;
405     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
406     nw = ((double)rc_edit.right - rc_edit.left) * dw;
407     nh = (double)(rc_edit.bottom - rc_edit.top) * dh;
408    
409     MoveWindow(GetDlgItem(hDlgWnd, IDC_EDIT),
410     rc_edit.left, rc_edit.top,
411     nw, nh, TRUE);
412    
413     #endif
414     }
415     return TRUE;
416    
417 maya 2476 default:
418     return FALSE;
419     }
420     return TRUE;
421     }
422    
423     //
424     // �N���b�v�{�[�h�����s�R�[�h�����������������A�m�F�_�C�A���O���\�������B
425     // �N���b�v�{�[�h�����X�����\�B
426     //
427     // return 0: Cancel
428     // 1: Paste OK
429     //
430     // (2008.2.3 yutaka)
431     //
432     int CBStartPasteConfirmChange(HWND HWin)
433     {
434     UINT Cf;
435     HANDLE hText;
436     char *pText;
437     int pos;
438     int ret = 0;
439    
440     if (ts.ConfirmChangePaste == 0)
441     return 1;
442    
443     if (! cv.Ready)
444     goto error;
445     if (TalkStatus!=IdTalkKeyb)
446     goto error;
447    
448     if (IsClipboardFormatAvailable(CF_TEXT))
449     Cf = CF_TEXT;
450     else if (IsClipboardFormatAvailable(CF_OEMTEXT))
451     Cf = CF_OEMTEXT;
452     else
453     goto error;
454    
455     if (!OpenClipboard(HWin))
456     goto error;
457    
458     hText = GetClipboardData(Cf);
459    
460     if (hText != NULL) {
461     pText = (char *)GlobalLock(hText);
462     pos = strcspn(pText, "\r\n"); // ���s����������������
463     if (pText[pos] != '\0') {
464     ClipboardPtr = pText;
465     PasteCanceled = 0;
466     ret = DialogBox(hInst, MAKEINTRESOURCE(IDD_CLIPBOARD_DIALOG),
467     HVTWin, (DLGPROC)OnClipboardDlgProc);
468     if (ret == 0 || ret == -1) {
469     ret = GetLastError();
470     }
471    
472     if (PasteCanceled) {
473     ret = 0;
474     GlobalUnlock(hText);
475     CloseClipboard();
476     goto error;
477     }
478    
479     }
480    
481     ret = 1;
482    
483     GlobalUnlock(hText);
484     }
485    
486     CloseClipboard();
487    
488     error:
489     return (ret);
490     }

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