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 9380 - (hide annotations) (download) (as text)
Fri Aug 20 16:31:56 2021 UTC (2 years, 7 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 8701 byte(s)
クリップボードペースト確認ダイアログが画面からはみ出さないようにした

- 本来はみ出さないようになっていた
- しかしダイアログサイズが変更されたときはみ出しがおこっていた
- 静的変数をなくした
- ts構造体の直接参照をなくした
- clipboarddlgdata の未使用メンバを削除した
- MoveWindowToDisplayPoint() を ttlib_static.c に追加
  - 指定座標が属するデスクトップから
  - ウィンドウをはみださないよう移動する
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3 nmaya 9048 * (C) 2006- TeraTerm Project
4 doda 6806 * All rights reserved.
5     *
6 doda 6841 * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9 doda 6806 *
10 doda 6841 * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17 doda 6806 *
18 doda 6841 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 doda 6806 */
29 maya 3227
30     /* TERATERM.EXE, Clipboard routines */
31     #include "teraterm.h"
32     #include "tttypes.h"
33     #include <string.h>
34     #include <stdlib.h>
35     #include <stdio.h>
36 doda 8445 #define _CRTDBG_MAP_ALLOC
37     #include <crtdbg.h>
38     #include <wchar.h>
39 maya 3227
40     #include "ttwinman.h"
41 doda 4769 #include "ttlib.h"
42 doda 8445 #include "codeconv.h"
43 maya 3227
44     #include "clipboar.h"
45 zmatsuo 8586 #include "fileread.h"
46 doda 8445 #include "sendmem.h"
47     #include "clipboarddlg.h"
48 maya 3227
49 doda 8445 static const wchar_t BracketStartW[] = L"\033[200~";
50     static const wchar_t BracketEndW[] = L"\033[201~";
51 doda 6456
52 doda 8445 static void TrimTrailingNLW(wchar_t *src)
53     {
54     wchar_t *tail = src + wcslen(src) - 1;
55     while(tail >= src) {
56     if (*tail != L'\r' && *tail != L'\n') {
57     break;
58     }
59     *tail = L'\0';
60     tail--;
61     }
62     }
63    
64 zmatsuo 8737 /**
65 doda 8445 * �t�@�C�������`���������������Atext���������������������B
66     * ���������� TRUE������
67     */
68     static BOOL search_dictW(char *filename, const wchar_t *text)
69     {
70     BOOL result = FALSE;
71     const wchar_t *buf_top = LoadFileWA(filename, NULL);
72     const wchar_t *buf = buf_top;
73     if (buf == NULL) {
74     return FALSE;
75     }
76    
77     for(;;) {
78     const wchar_t *line_end;
79     size_t len;
80     wchar_t *search_str;
81     if (*buf == 0) {
82     break;
83     }
84     if (*buf == '\r' || *buf == '\n') {
85     buf++;
86     continue;
87     }
88     line_end = wcspbrk(buf, L"\r\n");
89     if (line_end == NULL) {
90     // ���s������
91     len = wcslen(buf);
92     if (len == 0) {
93     // �I��
94     break;
95     }
96     } else {
97     len = line_end - buf;
98     }
99     search_str = (wchar_t *)malloc(sizeof(wchar_t) * (len+1));
100     if (search_str == NULL)
101     continue;
102     memcpy(search_str, buf, sizeof(wchar_t) * len);
103     search_str[len] = 0;
104     buf += len;
105     result = (wcsstr(text, search_str) != NULL);
106     free(search_str);
107     if (result) {
108     result = TRUE;
109     break;
110     }
111     }
112     free((void *)buf_top);
113     return result;
114     }
115    
116 doda 6456 /*
117     * �N���b�v�{�[�h�����e���m�F���A�\���t�����s�����m�F�_�C�A���O���o���B
118     *
119     * �����l:
120     * TRUE -> ���������A�\���t�������{
121     * FALSE -> �\���t�����~
122     */
123 zmatsuo 8736 static BOOL CheckClipboardContentW(HWND HWin, const wchar_t *str_w, BOOL AddCR, wchar_t **out_str_w)
124 doda 6456 {
125 zmatsuo 8736 INT_PTR ret;
126 doda 6456 BOOL confirm = FALSE;
127    
128 zmatsuo 8736 *out_str_w = NULL;
129 doda 6594 if ((ts.PasteFlag & CPF_CONFIRM_CHANGEPASTE) == 0) {
130 doda 6456 return TRUE;
131     }
132    
133     /*
134     * ConfirmChangePasteCR ����������
135     * �����������������������B
136     *
137     * ChangePasteCR !ChangePasteCR
138     * AddCR !AddCR AddCR !AddCR
139     * ���s���� o o x(2) o
140     * ���s���� o(1) x x x
141     *
142     * ChangePasteCR �� AddCR �������m�F���s����(1���m�F����)���������������A
143     * !ChangePasteCR �������l�������AAddCR ���������� CR ����������������
144     * �m�F���s������������ 2 �����������m�F���s�p���������v�\�������������B
145     * 2 ����������������������?
146     */
147     if (AddCR) {
148 doda 6594 if (ts.PasteFlag & CPF_CONFIRM_CHANGEPASTE_CR) {
149 doda 6456 confirm = TRUE;
150     }
151     }
152     else {
153 doda 8445 size_t pos = wcscspn(str_w, L"\r\n"); // ���s����������������
154     if (str_w[pos] != '\0') {
155     confirm = TRUE;
156     }
157     }
158    
159     // �������T�[�`����
160     if (!confirm && search_dictW(ts.ConfirmChangePasteStringFile, str_w)) {
161     confirm = TRUE;
162     }
163    
164     ret = IDOK;
165     if (confirm) {
166     clipboarddlgdata dlg_data;
167     dlg_data.strW_ptr = str_w;
168 zmatsuo 9359 dlg_data.UILanguageFileW = ts.UILanguageFileW;
169 zmatsuo 9380 dlg_data.PasteDialogSize = ts.PasteDialogSize;
170 doda 8445 ret = clipboarddlg(hInst, HWin, &dlg_data);
171 zmatsuo 9380 ts.PasteDialogSize = dlg_data.PasteDialogSize;
172 doda 8445 *out_str_w = dlg_data.strW_edited_ptr;
173     }
174    
175     if (ret == IDOK) {
176     return TRUE;
177     }
178     else {
179     return FALSE;
180     }
181     }
182    
183     /**
184     * �N���b�v�{�[�h�p�e�L�X�g���M����
185     *
186     * @param str_w �����������|�C���^
187     * malloc()�������o�b�t�@�A���M��������������free()������
188     */
189 zmatsuo 8788 static void CBSendStart(wchar_t *str_w)
190 doda 8445 {
191 zmatsuo 8788 SendMem *sm = SendMemTextW(str_w, 0);
192 zmatsuo 8920 if (sm == NULL) {
193     free(str_w);
194 doda 8445 return;
195 zmatsuo 8920 }
196 zmatsuo 8588 if (ts.PasteDelayPerLine == 0) {
197     SendMemInitDelay(sm, SENDMEM_DELAYTYPE_NO_DELAY, 0, 0);
198 doda 8445 }
199 zmatsuo 8588 else {
200     SendMemInitDelay(sm, SENDMEM_DELAYTYPE_PER_LINE, ts.PasteDelayPerLine, 0);
201     }
202 doda 8445 #if 0
203     SendMemInitDialog(sm, hInst, HVTWin, ts.UILanguageFile);
204     SendMemInitDialogCaption(sm, L"from clipboard");
205     SendMemInitDialogFilename(sm, L"Clipboard");
206     #endif
207     SendMemStart(sm);
208     }
209    
210     void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed)
211     {
212     wchar_t *str_w;
213     wchar_t *str_w_edited;
214    
215     if (! cv.Ready) {
216     return;
217     }
218     if (TalkStatus!=IdTalkKeyb) {
219     return;
220     }
221    
222     str_w = GetClipboardTextW(HWin, FALSE);
223 zmatsuo 8796 if (str_w == NULL || !IsTextW(str_w, 0)) {
224 doda 8445 // �N���b�v�{�[�h����������������������������
225     return;
226     }
227    
228     if (ts.PasteFlag & CPF_TRIM_TRAILING_NL) {
229     // �o�b�t�@���������s������
230     TrimTrailingNLW(str_w);
231     }
232    
233 zmatsuo 8459 {
234 zmatsuo 8919 // ���s�� CR+LF �����K���A�_�C�A���O�����s���������\����������
235     wchar_t *dest = NormalizeLineBreakCRLF(str_w);
236 doda 8445 free(str_w);
237     str_w = dest;
238     }
239    
240     if (!CheckClipboardContentW(HWin, str_w, AddCR, &str_w_edited)) {
241 zmatsuo 8738 free(str_w);
242 doda 8445 return;
243     }
244     if (str_w_edited != NULL) {
245     // �_�C�A���O�����W������
246     free(str_w);
247     str_w = str_w_edited;
248     }
249    
250     if (AddCR) {
251     size_t str_len = wcslen(str_w) + 2;
252     str_w = realloc(str_w, sizeof(wchar_t) * str_len);
253     str_w[str_len-2] = L'\r';
254     str_w[str_len-1] = 0;
255     }
256    
257 zmatsuo 8920 {
258     // ���s�� CR ���������K��
259     wchar_t *dest = NormalizeLineBreakCR(str_w, 0);
260     free(str_w);
261     str_w = dest;
262     }
263    
264 doda 8445 if (Bracketed) {
265     const size_t BracketStartLenW = _countof(BracketStartW) - 1;
266     const size_t BracketEndLenW = _countof(BracketEndW) - 1;
267     size_t str_len = wcslen(str_w);
268     size_t dest_len = str_len + BracketStartLenW + BracketEndLenW;
269     wchar_t *dest = malloc(sizeof(wchar_t) * (dest_len+1));
270     size_t i = 0;
271     wmemcpy(&dest[i], BracketStartW, BracketStartLenW);
272     i += BracketStartLenW;
273     wmemcpy(&dest[i], str_w, str_len);
274     i += str_len;
275     wmemcpy(&dest[i], BracketEndW, BracketEndLenW);
276     i += BracketEndLenW;
277     dest[i] = 0;
278     free(str_w);
279     str_w = dest;
280     }
281    
282 zmatsuo 8788 CBSendStart(str_w);
283 doda 8445 }
284    
285 doda 4769 void CBStartPasteB64(HWND HWin, PCHAR header, PCHAR footer)
286     {
287 doda 8445 size_t mb_len, b64_len, header_len = 0, footer_len = 0;
288     wchar_t *str_w = NULL;
289     char *str_mb = NULL;
290     char *str_b64 = NULL;
291    
292     if (! cv.Ready) {
293     return;
294     }
295     if (TalkStatus!=IdTalkKeyb) {
296     return;
297     }
298    
299     str_w = GetClipboardTextW(HWin, FALSE);
300 zmatsuo 8796 if (str_w == NULL || !IsTextW(str_w, 0)) {
301 doda 8445 // �N���b�v�{�[�h����������������������������
302     goto error;
303     }
304    
305     if (ts.Language == IdUtf8 || ts.KanjiCodeSend == IdUTF8) {
306     str_mb = ToU8W(str_w);
307     }
308     else {
309     str_mb = ToCharW(str_w);
310     }
311    
312     if (str_mb == NULL) {
313     goto error;
314     }
315    
316     if (header != NULL) {
317     header_len = strlen(header);
318     }
319     if (footer != NULL) {
320     footer_len = strlen(footer);
321     }
322    
323     mb_len = strlen(str_mb);
324     b64_len = (mb_len + 2) / 3 * 4 + header_len + footer_len + 1;
325    
326     if ((str_b64 = malloc(b64_len)) == NULL) {;
327     goto error;
328     }
329    
330     if (header_len > 0) {
331     strncpy_s(str_b64, b64_len, header, _TRUNCATE);
332     }
333    
334     b64encode(str_b64 + header_len, b64_len - header_len, str_mb, mb_len);
335    
336     if (footer_len > 0) {
337     strncat_s(str_b64, b64_len, footer, _TRUNCATE);
338     }
339    
340     free(str_w);
341     if ((str_w = ToWcharA(str_b64)) == NULL) {
342     goto error;
343     }
344    
345     free(str_mb);
346     free(str_b64);
347    
348     // �\���t�����������������o����
349 zmatsuo 8788 CBSendStart(str_w);
350 doda 8445
351     return;
352    
353     error:
354     free(str_w);
355     free(str_mb);
356     free(str_b64);
357     return;
358     }

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