• R/O
  • SSH
  • HTTPS

ttssh2: 提交


Commit MetaInfo

修订版8658 (tree)
时间2020-03-31 00:19:44
作者zmatsuo

Log Message

Clipb2Var を Unicode 対応にした

- 不要な include を削除

更改概述

差异

--- branches/unicode_macro_2/teraterm/ttpmacro/ttl_gui.cpp (revision 8657)
+++ branches/unicode_macro_2/teraterm/ttpmacro/ttl_gui.cpp (revision 8658)
@@ -35,18 +35,12 @@
3535 #include <stdio.h>
3636 #include <crtdbg.h>
3737 #include <string.h>
38-#include <mbstring.h>
39-#include <time.h>
40-#include <errno.h>
4138 #include "ttmdlg.h"
42-#include "ttmbuff.h"
4339 #include "ttmparse.h"
44-#include "ttmdde.h"
4540 #include "ttmlib.h"
4641 #include "ttlib.h"
4742 #include "ttmenc.h"
4843 #include "tttypes.h"
49-#include "ttmonig.h"
5044 #include "ttmacro.h"
5145 #include "ttl.h"
5246 #include "ttl_gui.h"
@@ -59,17 +53,9 @@
5953 {
6054 WORD Err;
6155 TVarId VarId;
62- HGLOBAL hText;
63- LPSTR clipbText;
64- char buf[MaxStrLen];
56+ static char *cbbuff;
57+ static int cblen;
6558 int Num = 0;
66- char *newbuff;
67- static char *cbbuff;
68- static int cbbuffsize, cblen;
69- HANDLE wide_hText;
70- LPWSTR wide_buf;
71- int mb_len;
72- UINT Cf;
7359
7460 Err = 0;
7561 GetStrVar(&VarId, &Err);
@@ -85,89 +71,24 @@
8571 if (Err!=0) return Err;
8672
8773 if (Num == 0) {
88- if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
89- Cf = CF_UNICODETEXT;
74+ if (cbbuff != NULL) {
75+ free(cbbuff);
76+ cbbuff = NULL;
9077 }
91- else if (IsClipboardFormatAvailable(CF_TEXT)) {
92- Cf = CF_TEXT;
93- }
94- else {
78+ wchar_t *cbbuffW = GetClipboardTextW(NULL, FALSE);
79+ if (cbbuffW == NULL) {
80+ // クリップボードを開けなかった。またはテキストデータではなかった。
9581 cblen = 0;
9682 SetResult(0);
97- return Err;
83+ return 0;
9884 }
99- if (OpenClipboard(NULL) == 0) {
100- cblen = 0;
101- SetResult(0);
102- return Err;
103- }
104-
105- if (Cf == CF_UNICODETEXT) {
106- wide_hText = GetClipboardData(CF_UNICODETEXT);
107- if (wide_hText != NULL) {
108- wide_buf = (LPWSTR)GlobalLock(wide_hText);
109- mb_len = WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, NULL, 0, NULL, NULL);
110- hText = GlobalAlloc(GMEM_MOVEABLE, sizeof(CHAR) * mb_len);
111- clipbText = (LPSTR)GlobalLock(hText);
112- if (hText != NULL) {
113- WideCharToMultiByte(CP_ACP, 0, wide_buf, -1, clipbText, mb_len, NULL, NULL);
114-
115- cblen = strlen(clipbText);
116- if (cbbuffsize <= cblen) {
117- if ((newbuff = (char *)realloc(cbbuff, cblen + 1)) == NULL) {
118- // realloc failed. fall back to old mode.
119- cblen = 0;
120- strncpy_s(buf,sizeof(buf),clipbText,_TRUNCATE);
121- GlobalUnlock(hText);
122- CloseClipboard();
123- SetStrVal(VarId, buf);
124- SetResult(3);
125- return Err;
126- }
127- cbbuff = newbuff;
128- cbbuffsize = cblen + 1;
129- }
130- strncpy_s(cbbuff, cbbuffsize, clipbText, _TRUNCATE);
131-
132- GlobalUnlock(hText);
133- GlobalFree(hText);
134- }
135- GlobalUnlock(wide_hText);
136- }
137- else {
138- cblen = 0;
139- }
140- }
141- else if (Cf == CF_TEXT) {
142- hText = GetClipboardData(CF_TEXT);
143- if (hText != NULL) {
144- clipbText = (LPSTR)GlobalLock(hText);
145- cblen = strlen(clipbText);
146- if (cbbuffsize <= cblen) {
147- if ((newbuff = (char *)realloc(cbbuff, cblen + 1)) == NULL) {
148- // realloc failed. fall back to old mode.
149- cblen = 0;
150- strncpy_s(buf,sizeof(buf),clipbText,_TRUNCATE);
151- GlobalUnlock(hText);
152- CloseClipboard();
153- SetStrVal(VarId, buf);
154- SetResult(3);
155- return Err;
156- }
157- cbbuff = newbuff;
158- cbbuffsize = cblen + 1;
159- }
160- strncpy_s(cbbuff, cbbuffsize, clipbText, _TRUNCATE);
161- GlobalUnlock(hText);
162- }
163- else {
164- cblen = 0;
165- }
166- }
167- CloseClipboard();
85+ cbbuff = ToU8W(cbbuffW);
86+ free(cbbuffW);
87+ cblen = 0;
16888 }
16989
17090 if (cbbuff != NULL && Num >= 0 && Num * (MaxStrLen - 1) < cblen) {
91+ char buf[MaxStrLen];
17192 if (strncpy_s(buf ,sizeof(buf), cbbuff + Num * (MaxStrLen-1), _TRUNCATE) == STRUNCATE)
17293 SetResult(2); // Copied string is truncated.
17394 else {
Show on old repository browser