[Ttssh2-commit] [8693] GetClipboardTextA(), GetClipboardTextW() を teraterm/common へ移動

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2020年 4月 12日 (日) 00:54:38 JST


Revision: 8693
          https://osdn.net/projects/ttssh2/scm/svn/commits/8693
Author:   zmatsuo
Date:     2020-04-12 00:54:37 +0900 (Sun, 12 Apr 2020)
Log Message:
-----------
GetClipboardTextA(), GetClipboardTextW() を teraterm/common へ移動

- ttlib_static_cpp.cpp へ
  - ttssh2/ttxssh/auth.c から
  - teraterm/teraterm/clipboar.c から

Modified Paths:
--------------
    trunk/teraterm/common/ttlib.h
    trunk/teraterm/common/ttlib_static_cpp.cpp
    trunk/teraterm/teraterm/clipboar.c
    trunk/ttssh2/ttxssh/auth.c

-------------- next part --------------
Modified: trunk/teraterm/common/ttlib.h
===================================================================
--- trunk/teraterm/common/ttlib.h	2020-04-11 15:54:28 UTC (rev 8692)
+++ trunk/teraterm/common/ttlib.h	2020-04-11 15:54:37 UTC (rev 8693)
@@ -147,6 +147,9 @@
 	COM_FLOWCTRL,
 };
 
+/*
+ *	ttlib_static
+ */
 typedef struct {
 	const char *section;			// \x83Z\x83N\x83V\x83\x87\x83\x93\x96\xBC
 	const char *title_key;			// \x83^\x83C\x83g\x83\x8B(NULL\x82̂Ƃ\xAB\x81Atitle_default \x82\xF0\x8F\xED\x82Ɏg\x97p)
@@ -157,6 +160,8 @@
 
 int TTMessageBoxW(HWND hWnd, const TTMessageBoxInfoW *info, UINT uType, const char *UILanguageFile, ...);
 wchar_t *TTGetLangStrW(const char *section, const char *key, const wchar_t *def, const char *UILanguageFile);
+wchar_t *GetClipboardTextW(HWND hWnd, BOOL empty);
+char *GetClipboardTextA(HWND hWnd, BOOL empty);
 
 #ifdef __cplusplus
 }

Modified: trunk/teraterm/common/ttlib_static_cpp.cpp
===================================================================
--- trunk/teraterm/common/ttlib_static_cpp.cpp	2020-04-11 15:54:28 UTC (rev 8692)
+++ trunk/teraterm/common/ttlib_static_cpp.cpp	2020-04-11 15:54:37 UTC (rev 8693)
@@ -103,7 +103,115 @@
 	return r;
 }
 
+/**
+ *	\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xA9\x82\xE7wchar_t\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x8E擾\x82\xB7\x82\xE9
+ *	\x95\xB6\x8E\x9A\x97񒷂\xAA\x95K\x97v\x82ȂƂ\xAB\x82\xCDwcslen()\x82\xB7\x82邱\x82\xC6
+ *	@param	hWnd
+ *	@param	emtpy	TRUE\x82̂Ƃ\xAB\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xF0\x8B\xF3\x82ɂ\xB7\x82\xE9
+ *	@retval	\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^ \x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6
+ *			\x95\xB6\x8E\x9A\x82\xAA\x82Ȃ\xA2(\x82܂\xBD\x82̓G\x83\x89\x81[\x8E\x9E)\x82\xCDNULL
+ */
+wchar_t *GetClipboardTextW(HWND hWnd, BOOL empty)
+{
+	UINT Cf;
+	wchar_t *str_w = NULL;
+	size_t str_w_len;
+	HGLOBAL TmpHandle;
 
+	if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
+		Cf = CF_UNICODETEXT;
+	}
+	else if (IsClipboardFormatAvailable(CF_TEXT)) {
+		Cf = CF_TEXT;
+	}
+	else if (IsClipboardFormatAvailable(CF_OEMTEXT)) {
+		Cf = CF_OEMTEXT;
+	}
+	else {
+		return NULL;
+	}
+
+ 	if (!OpenClipboard(hWnd)) {
+		return NULL;
+	}
+	TmpHandle = GetClipboardData(Cf);
+	if (TmpHandle == NULL) {
+		return NULL;
+	}
+	if (Cf == CF_UNICODETEXT) {
+		const wchar_t *str_cb = (wchar_t *)GlobalLock(TmpHandle);
+		if (str_cb != NULL) {
+			size_t str_cb_len = GlobalSize(TmpHandle);	// bytes
+			str_w_len = str_cb_len / sizeof(wchar_t);
+			str_w = (wchar_t *)malloc((str_w_len + 1) * sizeof(wchar_t));	// +1 for terminator
+			if (str_w != NULL) {
+				memcpy(str_w, str_cb, str_cb_len);
+				str_w[str_w_len] = L'\0';
+			}
+		}
+	}
+	else {
+		const char *str_cb = (char *)GlobalLock(TmpHandle);
+		if (str_cb != NULL) {
+			size_t str_cb_len = GlobalSize(TmpHandle);
+			str_w_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, str_cb, (int)str_cb_len, NULL, 0);
+			str_w = (wchar_t *)malloc(sizeof(wchar_t) * (str_w_len + 1));	// +1 for terminator
+			if (str_w != NULL) {
+				str_w_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, str_cb, (int)str_cb_len, str_w, (int)str_w_len);
+				str_w[str_w_len] = L'\0';
+			}
+		}
+	}
+	GlobalUnlock(TmpHandle);
+	if (empty) {
+		EmptyClipboard();
+	}
+	CloseClipboard();
+	return str_w;
+}
+
+/**
+ *	\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xA9\x82\xE7ANSI\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x8E擾\x82\xB7\x82\xE9
+ *	\x95\xB6\x8E\x9A\x97񒷂\xAA\x95K\x97v\x82ȂƂ\xAB\x82\xCDstrlen()\x82\xB7\x82邱\x82\xC6
+ *	@param	hWnd
+ *	@param	emtpy	TRUE\x82̂Ƃ\xAB\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xF0\x8B\xF3\x82ɂ\xB7\x82\xE9
+ *	@retval	\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^ \x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6
+ *			\x95\xB6\x8E\x9A\x82\xAA\x82Ȃ\xA2(\x82܂\xBD\x82̓G\x83\x89\x81[\x8E\x9E)\x82\xCDNULL
+ */
+char *GetClipboardTextA(HWND hWnd, BOOL empty)
+{
+	HGLOBAL hGlobal;
+	const char *lpStr;
+	size_t length;
+	char *pool;
+
+    OpenClipboard(hWnd);
+    hGlobal = (HGLOBAL)GetClipboardData(CF_TEXT);
+    if (hGlobal == NULL) {
+        CloseClipboard();
+		return NULL;
+    }
+    lpStr = (const char *)GlobalLock(hGlobal);
+	length = GlobalSize(hGlobal);
+	if (length == 0) {
+		pool = NULL;
+	} else {
+		pool = (char *)malloc(length + 1);	// +1 for terminator
+		memcpy(pool, lpStr, length);
+		pool[length] = '\0';
+	}
+	GlobalUnlock(hGlobal);
+	if (empty) {
+		EmptyClipboard();
+	}
+	CloseClipboard();
+
+	return pool;
+}
+
+
+
+
 // from ttxssh
 static void format_line_hexdump(char *buf, int buflen, int addr, int *bytes, int byte_cnt)
 {

Modified: trunk/teraterm/teraterm/clipboar.c
===================================================================
--- trunk/teraterm/teraterm/clipboar.c	2020-04-11 15:54:28 UTC (rev 8692)
+++ trunk/teraterm/teraterm/clipboar.c	2020-04-11 15:54:37 UTC (rev 8693)
@@ -724,75 +724,6 @@
 }
 #endif
 
-/**
- *	\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xA9\x82\xE7wchar_t\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x8E擾\x82\xB7\x82\xE9
- *	\x95\xB6\x8E\x9A\x97񒷂\xAA\x95K\x97v\x82ȂƂ\xAB\x82\xCDwcslen()\x82\xB7\x82邱\x82\xC6
- *	@param	hWnd
- *	@param	emtpy	TRUE\x82̂Ƃ\xAB\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xF0\x8B\xF3\x82ɂ\xB7\x82\xE9
- *	@retval	\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^ \x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6
- *			\x95\xB6\x8E\x9A\x82\xAA\x82Ȃ\xA2(\x82܂\xBD\x82̓G\x83\x89\x81[\x8E\x9E)\x82\xCDNULL
- *
- *	TODO ttssh2/ttxssh/auth.c \x82\xCC GetClipboardTextA() \x82̒u\x82\xAB\x8A\xB7\x82\xA6
- */
-static wchar_t *GetClipboardTextW(HWND hWnd, BOOL empty)
-{
-	UINT Cf;
-	wchar_t *str_w = NULL;
-	size_t str_w_len;
-	HGLOBAL TmpHandle;
-
-	if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
-		Cf = CF_UNICODETEXT;
-	}
-	else if (IsClipboardFormatAvailable(CF_TEXT)) {
-		Cf = CF_TEXT;
-	}
-	else if (IsClipboardFormatAvailable(CF_OEMTEXT)) {
-		Cf = CF_OEMTEXT;
-	}
-	else {
-		return NULL;
-	}
-
- 	if (!OpenClipboard(hWnd)) {
-		return NULL;
-	}
-	TmpHandle = GetClipboardData(Cf);
-	if (TmpHandle == NULL) {
-		return NULL;
-	}
-	if (Cf == CF_UNICODETEXT) {
-		const wchar_t *str_cb = (wchar_t *)GlobalLock(TmpHandle);
-		if (str_cb != NULL) {
-			size_t str_cb_len = GlobalSize(TmpHandle);	// bytes
-			str_w_len = str_cb_len / sizeof(wchar_t);
-			str_w = malloc((str_w_len + 1) * sizeof(wchar_t));	// +1 for terminator
-			if (str_w != NULL) {
-				memcpy(str_w, str_cb, str_cb_len);
-				str_w[str_w_len] = L'\0';
-			}
-		}
-	}
-	else {
-		const char *str_cb = (char *)GlobalLock(TmpHandle);
-		if (str_cb != NULL) {
-			size_t str_cb_len = GlobalSize(TmpHandle);
-			str_w_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, str_cb, (int)str_cb_len, NULL, 0);
-			str_w = malloc(sizeof(wchar_t) * (str_w_len + 1));	// +1 for terminator
-			if (str_w != NULL) {
-				str_w_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, str_cb, (int)str_cb_len, str_w, (int)str_w_len);
-				str_w[str_w_len] = L'\0';
-			}
-		}
-	}
-	GlobalUnlock(TmpHandle);
-	if (empty) {
-		EmptyClipboard();
-	}
-	CloseClipboard();
-	return str_w;
-}
-
 #if UNICODE_INTERNAL_BUFF
 /**
  *	\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x97p\x83e\x83L\x83X\x83g\x91\x97\x90M\x82\xB7\x82\xE9

Modified: trunk/ttssh2/ttxssh/auth.c
===================================================================
--- trunk/ttssh2/ttxssh/auth.c	2020-04-11 15:54:28 UTC (rev 8692)
+++ trunk/ttssh2/ttxssh/auth.c	2020-04-11 15:54:37 UTC (rev 8693)
@@ -739,46 +739,6 @@
 	return TRUE;
 }
 
-/**
- *	\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xA9\x82\xE7ANSI\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x8E擾\x82\xB7\x82\xE9
- *	\x95\xB6\x8E\x9A\x97񒷂\xAA\x95K\x97v\x82ȂƂ\xAB\x82\xCDstrlen()\x82\xB7\x82邱\x82\xC6
- *	@param	hWnd
- *	@param	emtpy	TRUE\x82̂Ƃ\xAB\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82\xF0\x8B\xF3\x82ɂ\xB7\x82\xE9
- *	@retval	\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^ \x8Eg\x97p\x8C\xE3free()\x82\xB7\x82邱\x82\xC6
- *			\x95\xB6\x8E\x9A\x82\xAA\x82Ȃ\xA2(\x82܂\xBD\x82̓G\x83\x89\x81[\x8E\x9E)\x82\xCDNULL
- */
-char *GetClipboardTextA(HWND hWnd, BOOL empty)
-{
-	HGLOBAL hGlobal;
-	const char *lpStr;
-	size_t length;
-	char *pool;
-
-    OpenClipboard(hWnd);
-    hGlobal = (HGLOBAL)GetClipboardData(CF_TEXT);
-    if (hGlobal == NULL) {
-        CloseClipboard();
-		return NULL;
-    }
-    lpStr = (const char *)GlobalLock(hGlobal);
-	length = GlobalSize(hGlobal);
-	if (length == 0) {
-		pool = NULL;
-	} else {
-		pool = (char *)malloc(length + 1);	// +1 for terminator
-		memcpy(pool, lpStr, length);
-		pool[length] = '\0';
-	}
-	GlobalUnlock(hGlobal);
-	if (empty) {
-		EmptyClipboard();
-	}
-	CloseClipboard();
-
-	return pool;
-}
-
-
 static INT_PTR CALLBACK auth_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
 									  LPARAM lParam)
 {


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