[Ttssh2-commit] [7995] クリップボードに文字列をコピーする関数を追加

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 8月 20日 (火) 23:33:58 JST


Revision: 7995
          https://osdn.net/projects/ttssh2/scm/svn/commits/7995
Author:   zmatsuo
Date:     2019-08-20 23:33:58 +0900 (Tue, 20 Aug 2019)
Log Message:
-----------
クリップボードに文字列をコピーする関数を追加

- CBSetTextW() 追加
- 未使用関数無効化

Modified Paths:
--------------
    branches/unicode_buf/teraterm/teraterm/buffer.c
    branches/unicode_buf/teraterm/teraterm/clipboar.c
    branches/unicode_buf/teraterm/teraterm/clipboar.h

-------------- next part --------------
Modified: branches/unicode_buf/teraterm/teraterm/buffer.c
===================================================================
--- branches/unicode_buf/teraterm/teraterm/buffer.c	2019-08-20 14:33:43 UTC (rev 7994)
+++ branches/unicode_buf/teraterm/teraterm/buffer.c	2019-08-20 14:33:58 UTC (rev 7995)
@@ -1864,17 +1864,7 @@
 	OutputDebugPrintfW(L"BuffCBCopyUnicode()\n"
 					   L"%d, '%s'\n", str_len, str_ptr);
 
-	// \x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82ɃZ\x83b\x83g
-	if (OpenClipboard(HVTWin)) {
-		HGLOBAL CBCopyWideHandle = GlobalAlloc(GMEM_MOVEABLE, sizeof(wchar_t) * str_len);
-		wchar_t *CBCopyWidePtr = (wchar_t *)GlobalLock(CBCopyWideHandle);
-		memcpy(CBCopyWidePtr, str_ptr, str_len * sizeof(wchar_t));
-		GlobalUnlock(CBCopyWideHandle);
-		EmptyClipboard();
-		SetClipboardData(CF_UNICODETEXT, CBCopyWideHandle);
-		// TODO 9x\x8Cn\x82ł͎\xA9\x93\xAE\x82\xC5CF_TEXT\x82ɃZ\x83b\x83g\x82\xB3\x82\xEA\x82Ȃ\xA2\x82炵\x82\xA2?
-		CloseClipboard();
-	}
+	CBSetTextW(HVTWin, str_ptr, 0);
 	free(str_ptr);
 }
 #endif

Modified: branches/unicode_buf/teraterm/teraterm/clipboar.c
===================================================================
--- branches/unicode_buf/teraterm/teraterm/clipboar.c	2019-08-20 14:33:43 UTC (rev 7994)
+++ branches/unicode_buf/teraterm/teraterm/clipboar.c	2019-08-20 14:33:58 UTC (rev 7995)
@@ -80,6 +80,7 @@
 
 static INT_PTR CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp);
 
+#if !UNICODE_BUF
 PCHAR CBOpen(LONG MemSize)
 {
 	if (MemSize==0) {
@@ -143,6 +144,7 @@
 	CBCopyHandle = NULL;
 	CBCopyWideHandle = NULL;
 }
+#endif
 
 void CBStartSend(PCHAR DataPtr, int DataSize, BOOL EchoOnly)
 {
@@ -1243,6 +1245,53 @@
 	_CrtCheckMemory();
 }
 
+/**
+ *	\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82Ƀe\x83L\x83X\x83g\x82\xF0\x83Z\x83b\x83g\x82\xB7\x82\xE9
+ *	str_w	\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82ɃZ\x83b\x83g\x82\xB7\x82镶\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
+ *			NULL\x82̂Ƃ\xAB\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xF0\x8B\xF3\x82ɂ\xB7\x82\xE9(str_len\x82͎Q\x8FƂ\xB3\x82\xEA\x82Ȃ\xA2)
+ *	str_len	\x95\xB6\x8E\x9A\x97\xF1\x92\xB7
+ *			0\x82̂Ƃ\xAB\x95\xB6\x8E\x9A\x97񒷂\xAA\x8E\xA9\x93\xAE\x82ŎZ\x8Fo\x82\xB3\x82\xEA\x82\xE9
+ */
+BOOL CBSetTextW(HWND hWnd, const wchar_t *str_w, size_t str_len)
+{
+	HGLOBAL CBCopyWideHandle;
+
+	if (str_w == NULL) {
+		str_len = 0;
+	} else {
+		if (str_len == 0)
+			str_len = wcslen(str_w);
+	}
+
+	if (!OpenClipboard(hWnd)) {
+		return FALSE;
+	}
+
+	EmptyClipboard();
+	if (str_len == 0) {
+		return TRUE;
+	}
+
+	{
+		// \x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83R\x83s\x81[\x81A\x8DŌ\xE3\x82\xCCL'\0'\x82\xE0\x8A܂߂\xE9
+		wchar_t *CBCopyWidePtr;
+		const size_t alloc_bytes = (str_len + 1) * sizeof(wchar_t);
+		CBCopyWideHandle = GlobalAlloc(GMEM_MOVEABLE, alloc_bytes);
+		CBCopyWidePtr = (wchar_t *)GlobalLock(CBCopyWideHandle);
+		memcpy(CBCopyWidePtr, str_w, alloc_bytes - sizeof(wchar_t));
+		CBCopyWidePtr[str_len] = L'\0';
+		GlobalUnlock(CBCopyWideHandle);
+	}
+
+	SetClipboardData(CF_UNICODETEXT, CBCopyWideHandle);
+
+	// TODO 9x\x8Cn\x82ł͎\xA9\x93\xAE\x82\xC5CF_TEXT\x82ɃZ\x83b\x83g\x82\xB3\x82\xEA\x82Ȃ\xA2\x82炵\x82\xA2?
+	CloseClipboard();
+
+	return TRUE;
+}
+
+#if 0
 BOOL CBSetClipboard(HWND owner, HGLOBAL hMem)
 {
 	char *buf;
@@ -1274,7 +1323,9 @@
 
 	return TRUE;
 }
+#endif
 
+#if 0
 HGLOBAL CBAllocClipboardMem(char *text)
 {
 	HGLOBAL hMem;
@@ -1292,6 +1343,7 @@
 
 	return hMem;
 }
+#endif
 
 static INT_PTR CALLBACK OnClipboardDlgProc(HWND hDlgWnd, UINT msg, WPARAM wp, LPARAM lp)
 {

Modified: branches/unicode_buf/teraterm/teraterm/clipboar.h
===================================================================
--- branches/unicode_buf/teraterm/teraterm/clipboar.h	2019-08-20 14:33:43 UTC (rev 7994)
+++ branches/unicode_buf/teraterm/teraterm/clipboar.h	2019-08-20 14:33:58 UTC (rev 7995)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1994-1998 T. Teranishi
- * (C) 2008-2017 TeraTerm Project
+ * (C) 2008-2019 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -29,13 +29,20 @@
 
 /* TERATERM.EXE, Clipboard routines */
 
+#include "unicode_test.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* prototypes */
+
+#if !UNICODE_INTERNAL_BUFF
 PCHAR CBOpen(LONG MemSize);
 void CBClose(void);
+#endif
+BOOL CBSetTextW(HWND hWnd, const wchar_t *str_w, size_t str_len);
+
 void CBStartSend(PCHAR DataPtr, int DataSize, BOOL EchoOnly);
 void CBStartPaste(HWND HWin, BOOL AddCR, BOOL Bracketed);
 void CBStartPasteW(HWND HWin, BOOL AddCR, BOOL Bracketed);
@@ -45,6 +52,7 @@
 void CBEcho(void);
 void CBEndPaste(void);
 
+
 #ifdef __cplusplus
 }
 #endif


Ttssh2-commit メーリングリストの案内
Back to archive index