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 8694 - (hide annotations) (download) (as text)
Sat Apr 11 15:54:46 2020 UTC (4 years ago) by zmatsuo
File MIME type: text/x-csrc
File size: 33060 byte(s)
CBSetTextW() を teraterm/common へ移動

- clipboar.c から ttlib_static_cpp.cpp へ
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3 zmatsuo 8459 * (C) 2006-2020 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 "vtdisp.h"
34 doda 7140 #include "vtterm.h"
35 maya 3227 #include <string.h>
36     #include <stdlib.h>
37     #include <stdio.h>
38 yutakapon 3635 #include <commctrl.h>
39 doda 8445 #define _CRTDBG_MAP_ALLOC
40     #include <crtdbg.h>
41     #include <wchar.h>
42 maya 3227
43     #include "ttwinman.h"
44     #include "ttcommon.h"
45 doda 4769 #include "ttlib.h"
46 zmatsuo 7509 #include "dlglib.h"
47 doda 8445 #include "codeconv.h"
48 maya 3227
49     #include "clipboar.h"
50     #include "tt_res.h"
51 zmatsuo 8586 #include "fileread.h"
52 doda 8445 #include "unicode_test.h"
53     #include "sendmem.h"
54     #include "clipboarddlg.h"
55 maya 3227
56     // for clipboard copy
57     static HGLOBAL CBCopyHandle = NULL;
58     static PCHAR CBCopyPtr = NULL;
59 maya 5071 static HGLOBAL CBCopyWideHandle = NULL;
60     static LPWSTR CBCopyWidePtr = NULL;
61 maya 3227
62     // for clipboard paste
63     static HGLOBAL CBMemHandle = NULL;
64     static PCHAR CBMemPtr = NULL;
65     static LONG CBMemPtr2 = 0;
66     static BYTE CBByte;
67     static BOOL CBRetrySend;
68     static BOOL CBRetryEcho;
69     static BOOL CBSendCR;
70 doda 3974 static BOOL CBEchoOnly;
71 doda 5259 static BOOL CBInsertDelay = FALSE;
72 maya 3227
73 doda 8445 static const wchar_t BracketStartW[] = L"\033[200~";
74     static const wchar_t BracketEndW[] = L"\033[201~";
75 doda 6456
76 doda 8445 static void CBEcho(void);
77     #if !UNICODE_INTERNAL_BUFF
78     static INT_PTR CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp);
79     #endif
80    
81     #if !UNICODE_INTERNAL_BUFF
82 maya 3227 PCHAR CBOpen(LONG MemSize)
83     {
84 maya 3393 if (MemSize==0) {
85     return (NULL);
86     }
87     if (CBCopyHandle!=NULL) {
88     return (NULL);
89     }
90     CBCopyPtr = NULL;
91     CBCopyHandle = GlobalAlloc(GMEM_MOVEABLE, MemSize);
92     if (CBCopyHandle == NULL) {
93     MessageBeep(0);
94     }
95     else {
96     CBCopyPtr = GlobalLock(CBCopyHandle);
97     if (CBCopyPtr == NULL) {
98     GlobalFree(CBCopyHandle);
99     CBCopyHandle = NULL;
100     MessageBeep(0);
101     }
102     }
103     return (CBCopyPtr);
104 maya 3227 }
105    
106     void CBClose()
107     {
108 maya 3393 BOOL Empty;
109 maya 5071 int WideCharLength;
110    
111 maya 3393 if (CBCopyHandle==NULL) {
112     return;
113     }
114 maya 3227
115 maya 5071 WideCharLength = MultiByteToWideChar(CP_ACP, 0, CBCopyPtr, -1, NULL, 0);
116     CBCopyWideHandle = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * WideCharLength);
117     if (CBCopyWideHandle) {
118     CBCopyWidePtr = (LPWSTR)GlobalLock(CBCopyWideHandle);
119     MultiByteToWideChar(CP_ACP, 0, CBCopyPtr, -1, CBCopyWidePtr, WideCharLength);
120     GlobalUnlock(CBCopyWideHandle);
121     }
122    
123 maya 3393 Empty = FALSE;
124     if (CBCopyPtr!=NULL) {
125     Empty = (CBCopyPtr[0]==0);
126     }
127 maya 3227
128 maya 3393 GlobalUnlock(CBCopyHandle);
129     CBCopyPtr = NULL;
130 maya 3227
131 maya 3393 if (OpenClipboard(HVTWin)) {
132     EmptyClipboard();
133     if (! Empty) {
134     SetClipboardData(CF_TEXT, CBCopyHandle);
135 maya 5071 if (CBCopyWidePtr) {
136     SetClipboardData(CF_UNICODETEXT, CBCopyWideHandle);
137     CBCopyWidePtr = NULL;
138     }
139 maya 3393 }
140     CloseClipboard();
141     }
142     CBCopyHandle = NULL;
143 maya 5071 CBCopyWideHandle = NULL;
144 maya 3227 }
145 doda 8445 #endif
146 maya 3227
147 doda 8445 /**
148     * ���������M
149     * ���������������g�p����������
150     * - DDE(TTL)
151     * - �u���[�h�L���X�g
152     */
153 doda 6440 void CBStartSend(PCHAR DataPtr, int DataSize, BOOL EchoOnly)
154 maya 3227 {
155 doda 6440 if (! cv.Ready) {
156     return;
157     }
158     if (TalkStatus!=IdTalkKeyb) {
159     return;
160     }
161    
162     CBEchoOnly = EchoOnly;
163    
164 doda 6452 if (CBMemHandle) {
165     GlobalFree(CBMemHandle);
166     }
167 doda 6440 CBMemHandle = NULL;
168     CBMemPtr = NULL;
169     CBMemPtr2 = 0;
170    
171     CBInsertDelay = FALSE;
172    
173     CBRetrySend = FALSE;
174     CBRetryEcho = FALSE;
175     CBSendCR = FALSE;
176    
177 doda 6535 if ((CBMemHandle = GlobalAlloc(GHND, DataSize+1)) != NULL) {
178 doda 6440 if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
179     memcpy(CBMemPtr, DataPtr, DataSize);
180 doda 6535 // WM_COPYDATA ���������������f�[�^�� NUL Terminate ���������������� NUL ���t������
181     CBMemPtr[DataSize] = 0;
182 doda 6440 GlobalUnlock(CBMemHandle);
183     CBMemPtr=NULL;
184     TalkStatus=IdTalkCB;
185     }
186     }
187     if (TalkStatus != IdTalkCB) {
188     CBEndPaste();
189     }
190     }
191    
192 doda 8445 #if !UNICODE_INTERNAL_BUFF
193 doda 6455 // �N���b�v�{�[�h�o�b�t�@������������ CR / LF ����������������
194 doda 8445 static BOOL TrimTrailingNL(BOOL AddCR, BOOL Bracketed)
195     {
196 doda 6455 PCHAR tail;
197 doda 6594 if (ts.PasteFlag & CPF_TRIM_TRAILING_NL) {
198 doda 6455 for (tail = CBMemPtr+strlen(CBMemPtr)-1; tail >= CBMemPtr; tail--) {
199     if (*tail != '\r' && *tail != '\n') {
200     break;
201     }
202     *tail = '\0';
203     }
204     }
205    
206     return TRUE;
207     }
208 doda 8445 #endif
209 doda 6455
210 doda 8445 static void TrimTrailingNLW(wchar_t *src)
211     {
212     wchar_t *tail = src + wcslen(src) - 1;
213     while(tail >= src) {
214     if (*tail != L'\r' && *tail != L'\n') {
215     break;
216     }
217     *tail = L'\0';
218     tail--;
219     }
220     }
221    
222 doda 6595 // ���s�� CR+LF �����K������
223 doda 8445 static BOOL NormalizeLineBreak(BOOL AddCR, BOOL Bracketed) {
224 doda 6595 char *p, *p2;
225     unsigned int len, need_len, alloc_len;
226     HGLOBAL TmpHandle;
227    
228     p = CBMemPtr;
229    
230     // �\���t���f�[�^������(len)�A���������K�������f�[�^������(need_len)���J�E���g
231     for (len=0, need_len=0, p=CBMemPtr; *p != '\0'; p++, len++, need_len++) {
232     if (*p == CR) {
233     need_len++;
234     if (*(p+1) == LF) {
235     len++;
236     p++;
237     }
238     }
239     else if (*p == LF) {
240     need_len++;
241     }
242     }
243    
244     // ���K�������f�[�^�������������� => ���K�����K�v����
245     if (need_len == len) {
246     return TRUE;
247     }
248    
249     // AddCR / Bracketed ���������������o�b�t�@���v�Z��������
250     // ������������������������������������
251     alloc_len = need_len + 1;
252     if (AddCR) {
253     alloc_len++;
254     }
255     if (Bracketed) {
256     // ������
257     alloc_len += 12;
258     }
259    
260     // �o�b�t�@�T�C�Y�����K�������K�v�������l�����������������o�b�t�@���m��������
261     if (GlobalSize(CBMemHandle) < alloc_len) {
262     GlobalUnlock(CBMemHandle);
263     CBMemPtr = NULL;
264     if ((TmpHandle = GlobalReAlloc(CBMemHandle, alloc_len, 0)) == NULL) {
265     // �������������������s
266     CBMemPtr = GlobalLock(CBMemHandle);
267    
268     // �������������K���������\���t������������
269     return TRUE;
270     }
271     CBMemHandle = TmpHandle;
272     CBMemPtr = GlobalLock(CBMemHandle);
273     }
274    
275     p = CBMemPtr + len - 1;
276     p2 = CBMemPtr + need_len;
277     *p2-- = '\0';
278    
279     while (len > 0 && p < p2) {
280     if (*p == LF) {
281     *p2-- = *p--;
282     if (--len == 0) {
283     *p2 = CR;
284     break;
285     }
286     if (*p != CR) {
287     *p2-- = CR;
288     if (p2 <= p) {
289     break;
290     }
291     else {
292     continue;
293     }
294     }
295     }
296     else if (*p == CR) {
297     *p2-- = LF;
298     if (p == p2)
299     break;
300     }
301     *p2-- = *p--;
302     len--;
303     }
304    
305     return TRUE;
306     }
307    
308 doda 8445 static wchar_t *NormalizeLineBreakW(const wchar_t *src_)
309     {
310     const wchar_t *src = src_;
311     wchar_t *dest_top;
312     wchar_t *dest;
313     size_t len, need_len, alloc_len;
314    
315     // �\���t���f�[�^������(len)�A���������K�������f�[�^������(need_len)���J�E���g
316     for (len=0, need_len=0, src=src_; *src != '\0'; src++, len++, need_len++) {
317     if (*src == CR) {
318     need_len++;
319     if (*(src+1) == LF) {
320     len++;
321     src++;
322     }
323     }
324     else if (*src == LF) {
325     need_len++;
326     }
327     }
328    
329     // ���K�������f�[�^�������������� => ���K�����K�v����
330     if (need_len == len) {
331     dest = _wcsdup(src_);
332     return dest;
333     }
334     alloc_len = need_len + 1;
335    
336     dest_top = (wchar_t *)malloc(sizeof(wchar_t) * alloc_len);
337    
338     src = src_ + len - 1;
339     dest = dest_top + need_len;
340     *dest-- = '\0';
341     len = need_len;
342    
343     while (len > 0 && dest_top <= dest) {
344     if (*src == LF) {
345     *dest-- = *src--;
346     if (--len == 0) {
347     *dest = CR;
348     break;
349     }
350     if (*src != CR) {
351     *dest-- = CR;
352     if (dest <= dest_top) {
353     break;
354     }
355     else {
356     continue;
357     }
358     }
359     }
360     else if (*src == CR) {
361     *dest-- = LF;
362     if (src == dest)
363     break;
364     }
365     *dest-- = *src--;
366     len--;
367     }
368    
369     return dest_top;
370     }
371    
372 doda 6456 // �t�@�C�������`���������������Atext���������������������B
373 doda 8445 static BOOL search_dict(char *filename, char *text)
374 doda 6456 {
375     BOOL ret = FALSE;
376     FILE *fp = NULL;
377     char buf[256];
378 doda 8445 size_t len;
379 doda 6456
380     if (filename == NULL || filename[0] == '\0')
381     return FALSE;
382    
383     if ((fp = fopen(filename, "r")) == NULL)
384     return FALSE;
385    
386     // TODO: ���s��256byte�������������������l��
387     while (fgets(buf, sizeof(buf), fp) != NULL) {
388     len = strlen(buf);
389     if (len <= 1) {
390     continue;
391     }
392     if (buf[len - 1] == '\n') {
393     buf[len - 1] = '\0';
394     }
395     if (strstr(text, buf)) { // hit
396     ret = 1;
397     break;
398     }
399     }
400    
401     fclose(fp);
402    
403     return (ret);
404     }
405    
406 doda 8445 /**
407     * �t�@�C�������`���������������Atext���������������������B
408     * ���������� TRUE������
409     */
410     static BOOL search_dictW(char *filename, const wchar_t *text)
411     {
412     BOOL result = FALSE;
413     const wchar_t *buf_top = LoadFileWA(filename, NULL);
414     const wchar_t *buf = buf_top;
415     if (buf == NULL) {
416     return FALSE;
417     }
418    
419     for(;;) {
420     const wchar_t *line_end;
421     size_t len;
422     wchar_t *search_str;
423     if (*buf == 0) {
424     break;
425     }
426     if (*buf == '\r' || *buf == '\n') {
427     buf++;
428     continue;
429     }
430     line_end = wcspbrk(buf, L"\r\n");
431     if (line_end == NULL) {
432     // ���s������
433     len = wcslen(buf);
434     if (len == 0) {
435     // �I��
436     break;
437     }
438     } else {
439     len = line_end - buf;
440     }
441     search_str = (wchar_t *)malloc(sizeof(wchar_t) * (len+1));
442     if (search_str == NULL)
443     continue;
444     memcpy(search_str, buf, sizeof(wchar_t) * len);
445     search_str[len] = 0;
446     buf += len;
447     result = (wcsstr(text, search_str) != NULL);
448     free(search_str);
449     if (result) {
450     result = TRUE;
451     break;
452     }
453     }
454     free((void *)buf_top);
455     return result;
456     }
457    
458 doda 6456 /*
459     * �N���b�v�{�[�h�����e���m�F���A�\���t�����s�����m�F�_�C�A���O���o���B
460     *
461     * �����l:
462     * TRUE -> ���������A�\���t�������{
463     * FALSE -> �\���t�����~
464     */
465 doda 8445 #if !UNICODE_INTERNAL_BUFF
466     static BOOL CheckClipboardContent(HWND HWin, BOOL AddCR, BOOL Bracketed)
467 doda 6456 {
468 doda 8445 INT_PTR ret = IDOK;
469 doda 6456 BOOL confirm = FALSE;
470    
471 doda 6594 if ((ts.PasteFlag & CPF_CONFIRM_CHANGEPASTE) == 0) {
472 doda 6456 return TRUE;
473     }
474    
475     /*
476     * ConfirmChangePasteCR ����������
477     * �����������������������B
478     *
479     * ChangePasteCR !ChangePasteCR
480     * AddCR !AddCR AddCR !AddCR
481     * ���s���� o o x(2) o
482     * ���s���� o(1) x x x
483     *
484     * ChangePasteCR �� AddCR �������m�F���s����(1���m�F����)���������������A
485     * !ChangePasteCR �������l�������AAddCR ���������� CR ����������������
486     * �m�F���s������������ 2 �����������m�F���s�p���������v�\�������������B
487     * 2 ����������������������?
488     */
489    
490     if (AddCR) {
491 doda 6594 if (ts.PasteFlag & CPF_CONFIRM_CHANGEPASTE_CR) {
492 doda 6456 confirm = TRUE;
493     }
494     }
495     else {
496 doda 8445 size_t pos = strcspn(CBMemPtr, "\r\n"); // ���s����������������
497 doda 6456 if (CBMemPtr[pos] != '\0') {
498     confirm = TRUE;
499     }
500     }
501    
502     // �������T�[�`����
503     if (!confirm && search_dict(ts.ConfirmChangePasteStringFile, CBMemPtr)) {
504     confirm = TRUE;
505     }
506    
507     if (confirm) {
508 zmatsuo 7509 ret = TTDialogBox(hInst, MAKEINTRESOURCE(IDD_CLIPBOARD_DIALOG),
509 doda 8445 HWin, OnClipboardDlgProc);
510 doda 6456 /*
511     * ���O���_�C�A���O�����e���N���b�v�{�[�h�����������������������A�K�v?
512     */
513     }
514    
515     if (ret == IDOK) {
516     return TRUE;
517     }
518     else {
519     return FALSE;
520     }
521     }
522 doda 8445 #endif
523 doda 6456
524 doda 8445 /*
525     * �N���b�v�{�[�h�����e���m�F���A�\���t�����s�����m�F�_�C�A���O���o���B
526     *
527     * �����l:
528     * TRUE -> ���������A�\���t�������{
529     * FALSE -> �\���t�����~
530     */
531     static BOOL CheckClipboardContentW(HWND HWin, const wchar_t *str_w, BOOL AddCR, wchar_t **out_str_w)
532     {
533     INT_PTR ret;
534     BOOL confirm = FALSE;
535    
536     *out_str_w = NULL;
537     if ((ts.PasteFlag & CPF_CONFIRM_CHANGEPASTE) == 0) {
538     return TRUE;
539     }
540    
541     if (AddCR) {
542     if (ts.PasteFlag & CPF_CONFIRM_CHANGEPASTE_CR) {
543     confirm = TRUE;
544     }
545     }
546     else {
547     size_t pos = wcscspn(str_w, L"\r\n"); // ���s����������������
548     if (str_w[pos] != '\0') {
549     confirm = TRUE;
550     }
551     }
552    
553     // �������T�[�`����
554     if (!confirm && search_dictW(ts.ConfirmChangePasteStringFile, str_w)) {
555     confirm = TRUE;
556     }
557    
558     ret = IDOK;
559     if (confirm) {
560     clipboarddlgdata dlg_data;
561     dlg_data.strW_ptr = str_w;
562     dlg_data.UILanguageFile = ts.UILanguageFile;
563     ret = clipboarddlg(hInst, HWin, &dlg_data);
564     *out_str_w = dlg_data.strW_edited_ptr;
565     }
566    
567     if (ret == IDOK) {
568     return TRUE;
569     }
570     else {
571     return FALSE;
572     }
573     }
574    
575     #if !UNICODE_INTERNAL_BUFF
576 doda 6440 void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed)
577     {
578 maya 3393 UINT Cf;
579 doda 6449 PCHAR TmpPtr;
580     LPWSTR TmpPtrW;
581     HGLOBAL TmpHandle;
582 doda 8445 size_t StrLen = 0, BuffLen = 0;
583 maya 3227
584 maya 3393 if (! cv.Ready) {
585     return;
586     }
587     if (TalkStatus!=IdTalkKeyb) {
588     return;
589     }
590 maya 3227
591 doda 6440 if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
592     Cf = CF_UNICODETEXT;
593 maya 3393 }
594 doda 6440 else if (IsClipboardFormatAvailable(CF_TEXT)) {
595     Cf = CF_TEXT;
596     }
597     else if (IsClipboardFormatAvailable(CF_OEMTEXT)) {
598     Cf = CF_OEMTEXT;
599     }
600     else {
601     return;
602     }
603 maya 3227
604 doda 3974 CBEchoOnly = FALSE;
605    
606 doda 6452 if (CBMemHandle) {
607     GlobalFree(CBMemHandle);
608     }
609 maya 3393 CBMemHandle = NULL;
610     CBMemPtr = NULL;
611     CBMemPtr2 = 0;
612 doda 5259
613 doda 6449 if (ts.PasteDelayPerLine > 0) {
614     CBInsertDelay = TRUE;
615     }
616     else {
617     CBInsertDelay = FALSE;
618     }
619    
620 doda 6440 CBRetrySend = FALSE;
621     CBRetryEcho = FALSE;
622     CBSendCR = FALSE;
623 maya 5071
624 doda 6440 if (OpenClipboard(HWin)) {
625 doda 6449 if ((TmpHandle = GetClipboardData(Cf)) != NULL) {
626     if (Cf == CF_UNICODETEXT) {
627     TmpPtrW = (LPWSTR)GlobalLock(TmpHandle);
628     BuffLen = WideCharToMultiByte(CP_ACP, 0, TmpPtrW, -1, 0, 0, NULL, NULL);
629     }
630     else {
631     TmpPtr = (PCHAR)GlobalLock(TmpHandle);
632     BuffLen = strlen(TmpPtr) + 1;
633     }
634 maya 5071
635 doda 6449 if (Bracketed) {
636 doda 6453 BuffLen += BracketStartLen + BracketEndLen;
637 doda 6449 }
638 maya 5071
639 doda 6449 if (AddCR) {
640     BuffLen++;
641     }
642    
643     if ((CBMemHandle = GlobalAlloc(GHND, BuffLen)) != NULL) {
644     if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
645     if (Cf == CF_UNICODETEXT) {
646 doda 8445 WideCharToMultiByte(CP_ACP, 0, TmpPtrW, -1, CBMemPtr, (int)BuffLen, NULL, NULL);
647 doda 6449 }
648     else {
649 doda 6453 strncpy_s(CBMemPtr, BuffLen, TmpPtr, _TRUNCATE);
650 doda 6449 }
651    
652     TalkStatus = IdTalkCB;
653 maya 5071 }
654     }
655 doda 6449 GlobalUnlock(TmpHandle);
656 maya 3393 }
657 doda 6449 CloseClipboard();
658 maya 3393 }
659 doda 6440
660 doda 6453 // �\���t�����������������o���������� IdTalkCB ������
661    
662 maya 3393 if (TalkStatus != IdTalkCB) {
663 doda 6453 // �������s�����������������\���t�������f����
664 maya 3393 CBEndPaste();
665 doda 6453 return;
666 maya 3393 }
667 doda 6453
668     // �\���t���O���N���b�v�{�[�h�����e���m�F/���H�������������������s��
669    
670 doda 6455 if (!TrimTrailingNL(AddCR, Bracketed)) {
671     CBEndPaste();
672     return;
673     }
674    
675 doda 6595 if (!NormalizeLineBreak(AddCR, Bracketed)) {
676     CBEndPaste();
677     return;
678     }
679    
680 doda 6459 if (!CheckClipboardContent(HWin, AddCR, Bracketed)) {
681 doda 6456 CBEndPaste();
682     return;
683     }
684    
685 doda 6453 // AddCR / Bracket �p�����������������m�F�A�������������m��
686     StrLen = strlen(CBMemPtr);
687     BuffLen = StrLen + 1; // strlen + NUL
688     if (AddCR) {
689     BuffLen++;
690     }
691     if (Bracketed) {
692     BuffLen += BracketStartLen + BracketEndLen;
693     }
694    
695     if (GlobalSize(CBMemHandle) < BuffLen) {
696     GlobalUnlock(CBMemHandle);
697     CBMemPtr = NULL;
698     if ((TmpHandle = GlobalReAlloc(CBMemHandle, BuffLen, 0)) == NULL) {
699     /*
700     * �s�������m�����s�������� CR/Bracket �������\���t�����s���������A
701     * ���������\���t�����������~����(CBEndPaste()������)�������B
702     */
703     // CBEndPaste();
704     return;
705     }
706     CBMemHandle = TmpHandle;
707     CBMemPtr = GlobalLock(CBMemHandle);
708     }
709    
710     if (AddCR) {
711     CBMemPtr[StrLen++] = '\r';
712 doda 6593 CBMemPtr[StrLen++] = 0;
713 doda 6453 }
714    
715     if (Bracketed) {
716     BuffLen = GlobalSize(CBMemHandle);
717     memmove_s(CBMemPtr+BracketStartLen, BuffLen-BracketStartLen, CBMemPtr, StrLen);
718     memcpy_s(CBMemPtr, BuffLen, BracketStart, BracketStartLen);
719     strncat_s(CBMemPtr, BuffLen, BracketEnd, _TRUNCATE);
720     }
721    
722     GlobalUnlock(CBMemHandle);
723     CBMemPtr = NULL;
724 maya 3227 }
725 doda 8445 #endif
726 maya 3227
727 doda 8445 #if UNICODE_INTERNAL_BUFF
728     /**
729     * �N���b�v�{�[�h�p�e�L�X�g���M����
730     *
731     * @param str_w �����������|�C���^
732     * malloc()�������o�b�t�@�A���M��������������free()������
733     * @param str_len ������(wchar_t�P��)
734 zmatsuo 8456 * 0 �������� L'\0' ����
735 doda 8445 */
736     static void CBSendStart(wchar_t *str_w, size_t str_len)
737     {
738     SendMem *sm;
739     if (str_len == 0) {
740     str_len = wcslen(str_w);
741     }
742 zmatsuo 8456 sm = SendMemTextW(str_w, str_len);
743 doda 8445 if (sm == NULL)
744     return;
745 zmatsuo 8588 if (ts.PasteDelayPerLine == 0) {
746     SendMemInitDelay(sm, SENDMEM_DELAYTYPE_NO_DELAY, 0, 0);
747 doda 8445 }
748 zmatsuo 8588 else {
749     SendMemInitDelay(sm, SENDMEM_DELAYTYPE_PER_LINE, ts.PasteDelayPerLine, 0);
750     }
751 doda 8445 #if 0
752     SendMemInitDialog(sm, hInst, HVTWin, ts.UILanguageFile);
753     SendMemInitDialogCaption(sm, L"from clipboard");
754     SendMemInitDialogFilename(sm, L"Clipboard");
755     #endif
756     SendMemStart(sm);
757     }
758     #endif
759    
760     #if UNICODE_INTERNAL_BUFF
761     void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed)
762     {
763     // unsigned int StrLen = 0;
764     wchar_t *str_w;
765     wchar_t *str_w_edited;
766    
767     if (! cv.Ready) {
768     return;
769     }
770     if (TalkStatus!=IdTalkKeyb) {
771     return;
772     }
773    
774     CBEchoOnly = FALSE;
775    
776     str_w = GetClipboardTextW(HWin, FALSE);
777     if (str_w == NULL) {
778     // �N���b�v�{�[�h����������������������������
779     CBEndPaste();
780     return;
781     }
782    
783     if (ts.PasteFlag & CPF_TRIM_TRAILING_NL) {
784     // �o�b�t�@���������s������
785     TrimTrailingNLW(str_w);
786     }
787    
788 zmatsuo 8459 {
789 doda 8445 // ���s�����K��
790     wchar_t *dest = NormalizeLineBreakW(str_w);
791     free(str_w);
792     str_w = dest;
793     }
794    
795     if (!CheckClipboardContentW(HWin, str_w, AddCR, &str_w_edited)) {
796     CBEndPaste();
797     return;
798     }
799     if (str_w_edited != NULL) {
800     // �_�C�A���O�����W������
801     free(str_w);
802     str_w = str_w_edited;
803     }
804    
805     if (AddCR) {
806     size_t str_len = wcslen(str_w) + 2;
807     str_w = realloc(str_w, sizeof(wchar_t) * str_len);
808     str_w[str_len-2] = L'\r';
809     str_w[str_len-1] = 0;
810     }
811    
812     if (Bracketed) {
813     const size_t BracketStartLenW = _countof(BracketStartW) - 1;
814     const size_t BracketEndLenW = _countof(BracketEndW) - 1;
815     size_t str_len = wcslen(str_w);
816     size_t dest_len = str_len + BracketStartLenW + BracketEndLenW;
817     wchar_t *dest = malloc(sizeof(wchar_t) * (dest_len+1));
818     size_t i = 0;
819     wmemcpy(&dest[i], BracketStartW, BracketStartLenW);
820     i += BracketStartLenW;
821     wmemcpy(&dest[i], str_w, str_len);
822     i += str_len;
823     wmemcpy(&dest[i], BracketEndW, BracketEndLenW);
824     i += BracketEndLenW;
825     dest[i] = 0;
826     free(str_w);
827     str_w = dest;
828     }
829    
830     CBSendStart(str_w, 0);
831     }
832     #endif
833    
834     #if !UNICODE_INTERNAL_BUFF
835 doda 4769 void CBStartPasteB64(HWND HWin, PCHAR header, PCHAR footer)
836     {
837     HANDLE tmpHandle = NULL;
838     char *tmpPtr = NULL;
839 doda 8445 size_t len, header_len, footer_len, b64_len;
840 maya 5071 UINT Cf;
841     LPWSTR tmpPtrWide = NULL;
842 doda 4769
843     if (! cv.Ready) {
844     return;
845     }
846     if (TalkStatus!=IdTalkKeyb) {
847     return;
848     }
849    
850     CBEchoOnly = FALSE;
851    
852 doda 6452 if (CBMemHandle) {
853     GlobalFree(CBMemHandle);
854     }
855 doda 4769 CBMemHandle = NULL;
856     CBMemPtr = NULL;
857     CBMemPtr2 = 0;
858    
859 doda 5259 if (ts.PasteDelayPerLine > 0) {
860     CBInsertDelay = TRUE;
861     }
862     else {
863     CBInsertDelay = FALSE;
864     }
865    
866 doda 6449 CBRetrySend = FALSE;
867     CBRetryEcho = FALSE;
868     CBSendCR = FALSE;
869    
870 maya 5071 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && OpenClipboard(HWin)) {
871     Cf = CF_UNICODETEXT;
872     if ((tmpHandle = GetClipboardData(CF_UNICODETEXT)) == NULL) {
873     CloseClipboard();
874     }
875     }
876     else if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(HWin)) {
877     Cf = CF_TEXT;
878 doda 4769 if ((tmpHandle = GetClipboardData(CF_TEXT)) == NULL) {
879     CloseClipboard();
880     }
881     }
882     else if (IsClipboardFormatAvailable(CF_OEMTEXT) && OpenClipboard(HWin)) {
883 maya 5071 Cf = CF_OEMTEXT;
884 doda 4769 if ((tmpHandle = GetClipboardData(CF_OEMTEXT)) == NULL) {
885     CloseClipboard();
886     }
887     }
888    
889 doda 6448 if (tmpHandle) {
890     if (Cf == CF_UNICODETEXT) {
891 maya 5071 if ((tmpPtrWide = GlobalLock(tmpHandle)) != NULL) {
892 doda 6448 len = WideCharToMultiByte(CP_ACP, 0, tmpPtrWide, -1, 0, 0, NULL, NULL);
893     if ((tmpPtr = (char *)calloc(sizeof(char), len)) != NULL) {
894     WideCharToMultiByte(CP_ACP, 0, tmpPtrWide, -1, tmpPtr, len, NULL, NULL);
895 maya 5071 }
896 doda 6448 // WideCharToMultiByte �������������������� \0 ����������
897     // \0 ���G���R�[�h������������������ 1 ������
898     len--;
899 doda 6461 GlobalUnlock(tmpHandle);
900 maya 5071 }
901     }
902 doda 6448 else {
903 maya 5071 if ((tmpPtr = GlobalLock(tmpHandle)) != NULL) {
904     len = strlen(tmpPtr);
905 doda 6448 }
906     }
907    
908     if (tmpPtr) {
909     header_len = strlen(header);
910     footer_len = strlen(footer);
911    
912     b64_len = (len + 2) / 3 * 4 + header_len + footer_len + 1;
913    
914     if ((CBMemHandle = GlobalAlloc(GHND, b64_len)) != NULL) {
915     if ((CBMemPtr = GlobalLock(CBMemHandle)) != NULL) {
916     if (header_len > 0) {
917     strncpy_s(CBMemPtr, b64_len, header, _TRUNCATE);
918 doda 4769 }
919 doda 6448 b64encode(CBMemPtr + header_len, b64_len - header_len, tmpPtr, len);
920     if (footer_len > 0) {
921     strncat_s(CBMemPtr, b64_len, footer, _TRUNCATE);
922     }
923     TalkStatus=IdTalkCB;
924     GlobalUnlock(CBMemPtr);
925     CBMemPtr = NULL;
926 doda 4769 }
927 doda 6448 }
928    
929     if (Cf == CF_UNICODETEXT) {
930     free(tmpPtr);
931     }
932     else {
933 doda 6461 GlobalUnlock(tmpHandle);
934 doda 4769 }
935     }
936 doda 6448 CloseClipboard();
937 doda 4769 }
938    
939     if (TalkStatus != IdTalkCB) {
940     CBEndPaste();
941     }
942     }
943 doda 8445 #endif
944 doda 4769
945 doda 8445 #if UNICODE_INTERNAL_BUFF
946     void CBStartPasteB64(HWND HWin, PCHAR header, PCHAR footer)
947     {
948     size_t mb_len, b64_len, header_len = 0, footer_len = 0;
949     wchar_t *str_w = NULL;
950     char *str_mb = NULL;
951     char *str_b64 = NULL;
952    
953     if (! cv.Ready) {
954     return;
955     }
956     if (TalkStatus!=IdTalkKeyb) {
957     return;
958     }
959    
960     CBEchoOnly = FALSE;
961    
962     str_w = GetClipboardTextW(HWin, FALSE);
963     if (str_w == NULL) {
964     // �N���b�v�{�[�h����������������������������
965     goto error;
966     }
967    
968     if (ts.Language == IdUtf8 || ts.KanjiCodeSend == IdUTF8) {
969     str_mb = ToU8W(str_w);
970     }
971     else {
972     str_mb = ToCharW(str_w);
973     }
974    
975     if (str_mb == NULL) {
976     goto error;
977     }
978    
979     if (header != NULL) {
980     header_len = strlen(header);
981     }
982     if (footer != NULL) {
983     footer_len = strlen(footer);
984     }
985    
986     mb_len = strlen(str_mb);
987     b64_len = (mb_len + 2) / 3 * 4 + header_len + footer_len + 1;
988    
989     if ((str_b64 = malloc(b64_len)) == NULL) {;
990     goto error;
991     }
992    
993     if (header_len > 0) {
994     strncpy_s(str_b64, b64_len, header, _TRUNCATE);
995     }
996    
997     b64encode(str_b64 + header_len, b64_len - header_len, str_mb, mb_len);
998    
999     if (footer_len > 0) {
1000     strncat_s(str_b64, b64_len, footer, _TRUNCATE);
1001     }
1002    
1003     free(str_w);
1004     if ((str_w = ToWcharA(str_b64)) == NULL) {
1005     goto error;
1006     }
1007    
1008     free(str_mb);
1009     free(str_b64);
1010    
1011     // �\���t�����������������o����
1012     CBSendStart(str_w, 0);
1013    
1014     return;
1015    
1016     error:
1017     free(str_w);
1018     free(str_mb);
1019     free(str_b64);
1020     CBEndPaste();
1021     return;
1022     }
1023     #endif
1024    
1025 maya 3227 // �����������N���b�v�{�[�h������DDE�f�[�^���[�������������B
1026     //
1027     // CBMemHandle�n���h�����O���[�o�������������A�����������I�������������A
1028     // �����N���b�v�{�[�h������DDE�f�[�^�������������������������i�j�����������\�������j�B
1029     // �����A�f�[�^���� null-terminate �����������������O�����������������A�������f�[�^����
1030     // �����������B
1031     // (2006.11.6 yutaka)
1032     void CBSend()
1033     {
1034 maya 3393 int c;
1035     BOOL EndFlag;
1036 doda 3688 static DWORD lastcr;
1037     DWORD now;
1038 maya 3227
1039 maya 3393 if (CBMemHandle==NULL) {
1040     return;
1041     }
1042 maya 3227
1043 doda 3974 if (CBEchoOnly) {
1044     CBEcho();
1045     return;
1046     }
1047    
1048 doda 5259 if (CBInsertDelay) {
1049     now = GetTickCount();
1050     if (now - lastcr < (DWORD)ts.PasteDelayPerLine) {
1051     return;
1052     }
1053 doda 3688 }
1054    
1055 maya 3393 if (CBRetrySend) {
1056     CBRetryEcho = (ts.LocalEcho>0);
1057     c = CommTextOut(&cv,(PCHAR)&CBByte,1);
1058     CBRetrySend = (c==0);
1059     if (CBRetrySend) {
1060     return;
1061     }
1062     }
1063 maya 3227
1064 maya 3393 if (CBRetryEcho) {
1065     c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
1066     CBRetryEcho = (c==0);
1067     if (CBRetryEcho) {
1068     return;
1069     }
1070     }
1071 maya 3227
1072 maya 4009 CBMemPtr = GlobalLock(CBMemHandle);
1073     if (CBMemPtr==NULL) {
1074 maya 3393 return;
1075     }
1076 maya 3227
1077 maya 3393 do {
1078     if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a)) {
1079     CBMemPtr2++;
1080     // added PasteDelayPerLine (2009.4.12 maya)
1081 doda 5259 if (CBInsertDelay) {
1082 doda 3690 lastcr = now;
1083     CBSendCR = FALSE;
1084     SetTimer(HVTWin, IdPasteDelayTimer, ts.PasteDelayPerLine, NULL);
1085     break;
1086     }
1087 maya 3393 }
1088    
1089     EndFlag = (CBMemPtr[CBMemPtr2]==0);
1090 doda 6449 if (! EndFlag) {
1091 maya 3393 CBByte = CBMemPtr[CBMemPtr2];
1092     CBMemPtr2++;
1093 maya 3227 // Decoding characters which are encoded by MACRO
1094     // to support NUL character sending
1095     //
1096     // [encoded character] --> [decoded character]
1097     // 01 01 --> 00
1098     // 01 02 --> 01
1099 maya 3393 if (CBByte==0x01) { /* 0x01 from MACRO */
1100     CBByte = CBMemPtr[CBMemPtr2];
1101     CBMemPtr2++;
1102     CBByte = CBByte - 1; // character just after 0x01
1103     }
1104     }
1105     else {
1106     CBEndPaste();
1107     return;
1108     }
1109 maya 3227
1110 maya 3393 if (! EndFlag) {
1111     c = CommTextOut(&cv,(PCHAR)&CBByte,1);
1112     CBSendCR = (CBByte==0x0D);
1113     CBRetrySend = (c==0);
1114     if ((! CBRetrySend) &&
1115     (ts.LocalEcho>0)) {
1116     c = CommTextEcho(&cv,(PCHAR)&CBByte,1);
1117     CBRetryEcho = (c==0);
1118     }
1119     }
1120     else {
1121     c=0;
1122     }
1123     }
1124     while (c>0);
1125 maya 3227
1126 maya 4009 if (CBMemPtr!=NULL) {
1127 maya 3393 GlobalUnlock(CBMemHandle);
1128     CBMemPtr=NULL;
1129     }
1130 maya 3227 }
1131    
1132 doda 8445 static void CBEcho()
1133 doda 3974 {
1134     if (CBMemHandle==NULL) {
1135     return;
1136     }
1137    
1138     if (CBRetryEcho && CommTextEcho(&cv,(PCHAR)&CBByte,1) == 0) {
1139     return;
1140     }
1141    
1142     if ((CBMemPtr = GlobalLock(CBMemHandle)) == NULL) {
1143     return;
1144     }
1145    
1146     do {
1147     if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a)) {
1148     CBMemPtr2++;
1149     }
1150    
1151     if (CBMemPtr[CBMemPtr2] == 0) {
1152     CBRetryEcho = FALSE;
1153     CBEndPaste();
1154     return;
1155     }
1156    
1157     CBByte = CBMemPtr[CBMemPtr2];
1158     CBMemPtr2++;
1159    
1160     // Decoding characters which are encoded by MACRO
1161     // to support NUL character sending
1162     //
1163     // [encoded character] --> [decoded character]
1164     // 01 01 --> 00
1165     // 01 02 --> 01
1166     if (CBByte==0x01) { /* 0x01 from MACRO */
1167     CBByte = CBMemPtr[CBMemPtr2];
1168     CBMemPtr2++;
1169     CBByte = CBByte - 1; // character just after 0x01
1170     }
1171    
1172     CBSendCR = (CBByte==0x0D);
1173    
1174     } while (CommTextEcho(&cv,(PCHAR)&CBByte,1) > 0);
1175    
1176     CBRetryEcho = TRUE;
1177    
1178     if (CBMemHandle != NULL) {
1179     GlobalUnlock(CBMemHandle);
1180     CBMemPtr=NULL;
1181     }
1182     }
1183    
1184 maya 3227 void CBEndPaste()
1185     {
1186 maya 3393 TalkStatus = IdTalkKeyb;
1187 maya 3227
1188 maya 3393 if (CBMemHandle!=NULL) {
1189     if (CBMemPtr!=NULL) {
1190     GlobalUnlock(CBMemHandle);
1191     }
1192 doda 6449 GlobalFree(CBMemHandle);
1193 maya 3393 }
1194 maya 3227
1195 maya 3393 CBMemHandle = NULL;
1196     CBMemPtr = NULL;
1197     CBMemPtr2 = 0;
1198 doda 3974 CBEchoOnly = FALSE;
1199 doda 5259 CBInsertDelay = FALSE;
1200 doda 8445 _CrtCheckMemory();
1201 maya 3227 }
1202    
1203 doda 8445 #if 0
1204 doda 6418 BOOL CBSetClipboard(HWND owner, HGLOBAL hMem)
1205     {
1206     char *buf;
1207     int wide_len;
1208     HGLOBAL wide_hMem;
1209 zmatsuo 7509 LPWSTR wide_buf = 0;
1210 maya 3227
1211 doda 6418 if (OpenClipboard(owner) == 0)
1212     return FALSE;
1213    
1214     buf = GlobalLock(hMem);
1215    
1216     wide_len = MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
1217     wide_hMem = GlobalAlloc(GMEM_MOVEABLE, sizeof(WCHAR) * wide_len);
1218     if (wide_hMem) {
1219     wide_buf = (LPWSTR)GlobalLock(wide_hMem);
1220     MultiByteToWideChar(CP_ACP, 0, buf, -1, wide_buf, wide_len);
1221     GlobalUnlock(wide_hMem);
1222     }
1223    
1224     GlobalUnlock(hMem);
1225    
1226     EmptyClipboard();
1227     SetClipboardData(CF_TEXT, hMem);
1228     if (wide_buf) {
1229     SetClipboardData(CF_UNICODETEXT, wide_hMem);
1230     }
1231     CloseClipboard();
1232    
1233     return TRUE;
1234     }
1235 doda 8445 #endif
1236 doda 6418
1237 doda 8445 #if 0
1238 doda 6418 HGLOBAL CBAllocClipboardMem(char *text)
1239     {
1240     HGLOBAL hMem;
1241     char *buf;
1242     int len;
1243    
1244     len = strlen(text);
1245    
1246     hMem = GlobalAlloc(GMEM_MOVEABLE, len+1);
1247     if (hMem) {
1248     buf = GlobalLock(hMem);
1249     strncpy_s(buf, len+1, text, _TRUNCATE);
1250     GlobalUnlock(hMem);
1251     }
1252    
1253     return hMem;
1254     }
1255 doda 8445 #endif
1256 doda 6418
1257 doda 8445 #if !UNICODE_INTERNAL_BUFF
1258     static INT_PTR CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
1259 maya 3227 {
1260 zmatsuo 7509 static const DlgTextInfo TextInfos[] = {
1261     { 0, "DLG_CLIPBOARD_TITLE" },
1262     { IDCANCEL, "BTN_CANCEL" },
1263     { IDOK, "BTN_OK" },
1264     };
1265 maya 3227 POINT p;
1266 zmatsuo 8408 RECT rc_dlg;
1267 maya 3902 static int ok2right, edit2ok, edit2bottom;
1268     RECT rc_edit, rc_ok, rc_cancel;
1269 yutakapon 3635 // for status bar
1270     static HWND hStatus = NULL;
1271 zmatsuo 7509 static int init_width, init_height;
1272 maya 3227
1273     switch (msg) {
1274     case WM_INITDIALOG:
1275 zmatsuo 7509 SetDlgTexts(hDlgWnd, TextInfos, _countof(TextInfos), ts.UILanguageFile);
1276 maya 3227
1277 zmatsuo 7509 SetDlgItemTextA(hDlgWnd, IDC_EDIT, CBMemPtr);
1278 maya 3227
1279 doda 6459 if (ActiveWin == IdVT) { // VT Window
1280     /*
1281     * Caret off ���� GetCaretPos() �����m���������������������A
1282     * vtdisp.c �������������������l�����v�Z����
1283     */
1284     DispConvScreenToWin(CursorX, CursorY, &p.x, &p.y);
1285     }
1286     else if (!GetCaretPos(&p)) { // Tek Window
1287     /*
1288     * Tek Window �������������l�������������|������ GetCaretPos() ���g��
1289     * GetCaretPos() ���G���[���������������O������ 0, 0 ������������
1290     */
1291     p.x = 0;
1292     p.y = 0;
1293     }
1294 maya 3227
1295 doda 6460 // x, y �������� 0 �������e�E�B���h�E���������������������������A
1296     // �������h������ x �� 1 ������
1297     if (p.x == 0 && p.y == 0) {
1298     p.x = 1;
1299     }
1300    
1301 doda 6459 ClientToScreen(GetParent(hDlgWnd), &p);
1302 maya 3227 SetWindowPos(hDlgWnd, NULL, p.x, p.y,
1303     0, 0, SWP_NOSIZE | SWP_NOZORDER);
1304 zmatsuo 8408 MoveWindowToDisplay(hDlgWnd);
1305 maya 3227
1306 maya 3641 // �_�C�A���O�������T�C�Y������
1307     GetWindowRect(hDlgWnd, &rc_dlg);
1308     init_width = rc_dlg.right - rc_dlg.left;
1309     init_height = rc_dlg.bottom - rc_dlg.top;
1310    
1311 maya 3227 // �����T�C�Y�����K�v���l���v�Z
1312     GetClientRect(hDlgWnd, &rc_dlg);
1313     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
1314     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
1315    
1316     p.x = rc_dlg.right;
1317     p.y = rc_dlg.bottom;
1318     ClientToScreen(hDlgWnd, &p);
1319     ok2right = p.x - rc_ok.left;
1320 maya 3902 edit2bottom = p.y - rc_edit.bottom;
1321 maya 3227 edit2ok = rc_ok.left - rc_edit.right;
1322    
1323     // �T�C�Y������
1324     SetWindowPos(hDlgWnd, NULL, 0, 0,
1325     ts.PasteDialogSize.cx, ts.PasteDialogSize.cy,
1326     SWP_NOZORDER | SWP_NOMOVE);
1327    
1328 yutakapon 3635 // ���T�C�Y�A�C�R�����E�����\���������������A�X�e�[�^�X�o�[���t�����B
1329     InitCommonControls();
1330     hStatus = CreateStatusWindow(
1331     WS_CHILD | WS_VISIBLE |
1332     CCS_BOTTOM | SBARS_SIZEGRIP, NULL, hDlgWnd, 1);
1333    
1334 maya 3227 return TRUE;
1335    
1336     case WM_COMMAND:
1337     switch (LOWORD(wp)) {
1338     case IDOK:
1339     {
1340 zmatsuo 7509 unsigned len = SendMessageA(GetDlgItem(hDlgWnd, IDC_EDIT), WM_GETTEXTLENGTH, 0, 0);
1341 maya 3227 HGLOBAL hMem;
1342 doda 6456 INT_PTR result = IDCANCEL;
1343 maya 3227
1344 doda 6456 if (CBMemHandle == NULL) {
1345     CBMemHandle = GlobalAlloc(GHND, len+1);
1346     }
1347     else if (GlobalSize(CBMemHandle) <= len) {
1348     if (CBMemPtr) {
1349     GlobalUnlock(CBMemHandle);
1350     CBMemPtr = NULL;
1351     }
1352     hMem = GlobalReAlloc(CBMemHandle, len+1, 0);
1353     if (hMem) {
1354     CBMemHandle = hMem;
1355     CBMemPtr = GlobalLock(CBMemHandle);
1356     }
1357     else {
1358     /*
1359     * ���������m�����������������������������������B
1360     *
1361     * �_�C�A���O�������������s�������������l������
1362     * �L�����Z�������������������������A����������������
1363     * �s���������v�����������A���������������������e��
1364     * �\���t���������e���B
1365     *
1366     * ���������������S�����|���A���������J�������\���t����
1367     * �s�������������������B
1368     */
1369     GlobalFree(CBMemHandle);
1370     CBMemHandle = NULL;
1371     }
1372     }
1373 doda 6417
1374 doda 6456 if (CBMemHandle) {
1375     if (CBMemPtr == NULL) {
1376     CBMemPtr = GlobalLock(CBMemHandle);
1377 maya 5071 }
1378 zmatsuo 7509 GetDlgItemTextA(hDlgWnd, IDC_EDIT, CBMemPtr, GlobalSize(CBMemHandle));
1379 doda 6456 result = IDOK;
1380 maya 3902 }
1381 maya 3227
1382 yutakapon 3635 DestroyWindow(hStatus);
1383 zmatsuo 7509 TTEndDialog(hDlgWnd, result);
1384 maya 3227 }
1385     break;
1386    
1387     case IDCANCEL:
1388 yutakapon 3635 DestroyWindow(hStatus);
1389 zmatsuo 7509 TTEndDialog(hDlgWnd, IDCANCEL);
1390 maya 3227 break;
1391    
1392     default:
1393     return FALSE;
1394     }
1395    
1396     case WM_SIZE:
1397     {
1398     // ���z�u
1399     POINT p;
1400     int dlg_w, dlg_h;
1401    
1402     GetClientRect(hDlgWnd, &rc_dlg);
1403     dlg_w = rc_dlg.right;
1404     dlg_h = rc_dlg.bottom;
1405    
1406     GetWindowRect(GetDlgItem(hDlgWnd, IDC_EDIT), &rc_edit);
1407     GetWindowRect(GetDlgItem(hDlgWnd, IDOK), &rc_ok);
1408     GetWindowRect(GetDlgItem(hDlgWnd, IDCANCEL), &rc_cancel);
1409    
1410     // OK
1411     p.x = rc_ok.left;
1412     p.y = rc_ok.top;
1413     ScreenToClient(hDlgWnd, &p);
1414     SetWindowPos(GetDlgItem(hDlgWnd, IDOK), 0,
1415     dlg_w - ok2right, p.y, 0, 0,
1416     SWP_NOSIZE | SWP_NOZORDER);
1417    
1418     // CANCEL
1419     p.x = rc_cancel.left;
1420     p.y = rc_cancel.top;
1421     ScreenToClient(hDlgWnd, &p);
1422     SetWindowPos(GetDlgItem(hDlgWnd, IDCANCEL), 0,
1423     dlg_w - ok2right, p.y, 0, 0,
1424     SWP_NOSIZE | SWP_NOZORDER);
1425    
1426     // EDIT
1427     p.x = rc_edit.left;
1428     p.y = rc_edit.top;
1429     ScreenToClient(hDlgWnd, &p);
1430     SetWindowPos(GetDlgItem(hDlgWnd, IDC_EDIT), 0,
1431 maya 3902 0, 0, dlg_w - p.x - edit2ok - ok2right, dlg_h - p.y - edit2bottom,
1432 maya 3227 SWP_NOMOVE | SWP_NOZORDER);
1433    
1434     // �T�C�Y������
1435     GetWindowRect(hDlgWnd, &rc_dlg);
1436     ts.PasteDialogSize.cx = rc_dlg.right - rc_dlg.left;
1437     ts.PasteDialogSize.cy = rc_dlg.bottom - rc_dlg.top;
1438 yutakapon 3635
1439     // status bar
1440     SendMessage(hStatus , msg , wp , lp);
1441 maya 3227 }
1442     return TRUE;
1443    
1444 maya 3641 case WM_GETMINMAXINFO:
1445     {
1446     // �_�C�A���O�������T�C�Y����������������������������
1447     LPMINMAXINFO lpmmi;
1448     lpmmi = (LPMINMAXINFO)lp;
1449     lpmmi->ptMinTrackSize.x = init_width;
1450     lpmmi->ptMinTrackSize.y = init_height;
1451     }
1452     return FALSE;
1453    
1454 maya 3227 default:
1455     return FALSE;
1456     }
1457     return TRUE;
1458     }
1459 doda 8445 #endif

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