• R/O
  • SSH
  • HTTPS

ttssh2: 提交


Commit MetaInfo

修订版8650 (tree)
时间2020-03-29 01:04:14
作者zmatsuo

Log Message

CBSetTextW() を teraterm/common へ移動

- clipboar.c から ttlib_static_cpp.cpp へ

更改概述

差异

--- branches/unicode_macro_2/teraterm/common/ttlib.h (revision 8649)
+++ branches/unicode_macro_2/teraterm/common/ttlib.h (revision 8650)
@@ -161,6 +161,7 @@
161161 wchar_t *TTGetLangStrW(const char *section, const char *key, const wchar_t *def, const char *UILanguageFile);
162162 wchar_t *GetClipboardTextW(HWND hWnd, BOOL empty);
163163 char *GetClipboardTextA(HWND hWnd, BOOL empty);
164+BOOL CBSetTextW(HWND hWnd, const wchar_t *str_w, size_t str_len);
164165
165166 #ifdef __cplusplus
166167 }
--- branches/unicode_macro_2/teraterm/common/ttlib_static_cpp.cpp (revision 8649)
+++ branches/unicode_macro_2/teraterm/common/ttlib_static_cpp.cpp (revision 8650)
@@ -209,4 +209,60 @@
209209 return pool;
210210 }
211211
212+/**
213+ * クリップボードにテキストをセットする
214+ * str_w クリップボードにセットする文字列へのポインタ
215+ * NULLのときクリップボードを空にする(str_lenは参照されない)
216+ * str_len 文字列長
217+ * 0のとき文字列長が自動で算出される
218+ */
219+BOOL CBSetTextW(HWND hWnd, const wchar_t *str_w, size_t str_len)
220+{
221+ HGLOBAL CBCopyWideHandle;
212222
223+ if (str_w == NULL) {
224+ str_len = 0;
225+ } else {
226+ if (str_len == 0)
227+ str_len = wcslen(str_w);
228+ }
229+
230+ if (!OpenClipboard(hWnd)) {
231+ return FALSE;
232+ }
233+
234+ EmptyClipboard();
235+ if (str_len == 0) {
236+ CloseClipboard();
237+ return TRUE;
238+ }
239+
240+ {
241+ // 文字列をコピー、最後のL'\0'も含める
242+ wchar_t *CBCopyWidePtr;
243+ const size_t alloc_bytes = (str_len + 1) * sizeof(wchar_t);
244+ CBCopyWideHandle = GlobalAlloc(GMEM_MOVEABLE, alloc_bytes);
245+ if (CBCopyWideHandle == NULL) {
246+ CloseClipboard();
247+ return FALSE;
248+ }
249+ CBCopyWidePtr = (wchar_t *)GlobalLock(CBCopyWideHandle);
250+ if (CBCopyWidePtr == NULL) {
251+ CloseClipboard();
252+ return FALSE;
253+ }
254+ memcpy(CBCopyWidePtr, str_w, alloc_bytes - sizeof(wchar_t));
255+ CBCopyWidePtr[str_len] = L'\0';
256+ GlobalUnlock(CBCopyWideHandle);
257+ }
258+
259+ SetClipboardData(CF_UNICODETEXT, CBCopyWideHandle);
260+
261+ // TODO 9x系では自動でCF_TEXTにセットされないらしい?
262+ // ttl_gui.c の TTLVar2Clipb() ではつぎの2つが行われていた
263+ // SetClipboardData(CF_TEXT, hText);
264+ // SetClipboardData(CF_UNICODETEXT, wide_hText);
265+ CloseClipboard();
266+
267+ return TRUE;
268+}
--- branches/unicode_macro_2/teraterm/teraterm/clipboar.c (revision 8649)
+++ branches/unicode_macro_2/teraterm/teraterm/clipboar.c (revision 8650)
@@ -1200,61 +1200,6 @@
12001200 _CrtCheckMemory();
12011201 }
12021202
1203-/**
1204- * クリップボードにテキストをセットする
1205- * str_w クリップボードにセットする文字列へのポインタ
1206- * NULLのときクリップボードを空にする(str_lenは参照されない)
1207- * str_len 文字列長
1208- * 0のとき文字列長が自動で算出される
1209- */
1210-BOOL CBSetTextW(HWND hWnd, const wchar_t *str_w, size_t str_len)
1211-{
1212- HGLOBAL CBCopyWideHandle;
1213-
1214- if (str_w == NULL) {
1215- str_len = 0;
1216- } else {
1217- if (str_len == 0)
1218- str_len = wcslen(str_w);
1219- }
1220-
1221- if (!OpenClipboard(hWnd)) {
1222- return FALSE;
1223- }
1224-
1225- EmptyClipboard();
1226- if (str_len == 0) {
1227- CloseClipboard();
1228- return TRUE;
1229- }
1230-
1231- {
1232- // 文字列をコピー、最後のL'\0'も含める
1233- wchar_t *CBCopyWidePtr;
1234- const size_t alloc_bytes = (str_len + 1) * sizeof(wchar_t);
1235- CBCopyWideHandle = GlobalAlloc(GMEM_MOVEABLE, alloc_bytes);
1236- if (CBCopyWideHandle == NULL) {
1237- CloseClipboard();
1238- return FALSE;
1239- }
1240- CBCopyWidePtr = (wchar_t *)GlobalLock(CBCopyWideHandle);
1241- if (CBCopyWidePtr == NULL) {
1242- CloseClipboard();
1243- return FALSE;
1244- }
1245- memcpy(CBCopyWidePtr, str_w, alloc_bytes - sizeof(wchar_t));
1246- CBCopyWidePtr[str_len] = L'\0';
1247- GlobalUnlock(CBCopyWideHandle);
1248- }
1249-
1250- SetClipboardData(CF_UNICODETEXT, CBCopyWideHandle);
1251-
1252- // TODO 9x系では自動でCF_TEXTにセットされないらしい?
1253- CloseClipboard();
1254-
1255- return TRUE;
1256-}
1257-
12581203 #if 0
12591204 BOOL CBSetClipboard(HWND owner, HGLOBAL hMem)
12601205 {
--- branches/unicode_macro_2/teraterm/teraterm/clipboar.h (revision 8649)
+++ branches/unicode_macro_2/teraterm/teraterm/clipboar.h (revision 8650)
@@ -41,7 +41,6 @@
4141 PCHAR CBOpen(LONG MemSize);
4242 void CBClose(void);
4343 #endif
44-BOOL CBSetTextW(HWND hWnd, const wchar_t *str_w, size_t str_len);
4544
4645 void CBStartSend(PCHAR DataPtr, int DataSize, BOOL EchoOnly);
4746 void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed);
Show on old repository browser