Revision: 8649 https://osdn.net/projects/ttssh2/scm/svn/commits/8649 Author: zmatsuo Date: 2020-03-29 01:04:03 +0900 (Sun, 29 Mar 2020) Log Message: ----------- GetClipboardTextA(), GetClipboardTextW() を teraterm/common へ移動 - ttlib_static_cpp.cpp へ - ttssh2/ttxssh/auth.c から - teraterm/teraterm/clipboar.c から Modified Paths: -------------- branches/unicode_macro_2/teraterm/common/ttlib.h branches/unicode_macro_2/teraterm/common/ttlib_static_cpp.cpp branches/unicode_macro_2/teraterm/teraterm/clipboar.c branches/unicode_macro_2/ttssh2/ttxssh/auth.c -------------- next part -------------- Modified: branches/unicode_macro_2/teraterm/common/ttlib.h =================================================================== --- branches/unicode_macro_2/teraterm/common/ttlib.h 2020-03-28 14:26:06 UTC (rev 8648) +++ branches/unicode_macro_2/teraterm/common/ttlib.h 2020-03-28 16:04:03 UTC (rev 8649) @@ -146,6 +146,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) @@ -156,6 +159,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: branches/unicode_macro_2/teraterm/common/ttlib_static_cpp.cpp =================================================================== --- branches/unicode_macro_2/teraterm/common/ttlib_static_cpp.cpp 2020-03-28 14:26:06 UTC (rev 8648) +++ branches/unicode_macro_2/teraterm/common/ttlib_static_cpp.cpp 2020-03-28 16:04:03 UTC (rev 8649) @@ -1,3 +1,31 @@ +/* + * Copyright (C) 1994-1998 T. Teranishi + * (C) 2006-2020 TeraTerm Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ #include <windows.h> #include <string.h> @@ -74,3 +102,111 @@ 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; +} + + Modified: branches/unicode_macro_2/teraterm/teraterm/clipboar.c =================================================================== --- branches/unicode_macro_2/teraterm/teraterm/clipboar.c 2020-03-28 14:26:06 UTC (rev 8648) +++ branches/unicode_macro_2/teraterm/teraterm/clipboar.c 2020-03-28 16:04:03 UTC (rev 8649) @@ -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: branches/unicode_macro_2/ttssh2/ttxssh/auth.c =================================================================== --- branches/unicode_macro_2/ttssh2/ttxssh/auth.c 2020-03-28 14:26:06 UTC (rev 8648) +++ branches/unicode_macro_2/ttssh2/ttxssh/auth.c 2020-03-28 16:04:03 UTC (rev 8649) @@ -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) {